1、 Dialog 弹框
AlertDialog Material
风格:
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text('提示'),
content: Text('确认删除吗?'),
backgroundColor: Colors.lightBlueAccent,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
actions: <Widget>[
FlatButton(child: Text('取消'),onPressed: (){
Navigator.of(context).pop('cancel');
},),
FlatButton(child: Text('确认'),onPressed: (){
Navigator.of(context).pop('ok');
},),
],
);
},
);
CupertinoAlertDialog IOS
的风格:
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('提示'),
content: Text('确认删除吗?'),
actions: <Widget>[
CupertinoDialogAction(child: Text('取消'),onPressed: (){},),
CupertinoDialogAction(child: Text('确认'),onPressed: (){},),
],
);
}
);
SimpleDialog
用法和 AlertDialog
基本相同
showDialog(
context: context,
builder: (context) {
return SimpleDialog(
title: Text('提示'),
children: <Widget>[
Container(
height: 80,
alignment: Alignment.center,
child: Text('确认删除吗?'),
),
Divider(height: 1,),
FlatButton(
child: Text('取消'),
onPressed: () {
Navigator.of(context).pop('cancel');
},
),
Divider(height: 1,),
FlatButton(
child: Text('确认'),
onPressed: () {
Navigator.of(context).pop('ok');
},
),
],
);
},
);
2、 Toast 提示
2.1 pubspec.yaml
中添加 fluttertoast
fluttertoast: ^3.1.3
2.2 在使用的组件文件中 引入该文件包、或者在公共组件中重新封装成你想要的样式
package:'fluttertoast/fluttertoast.dart';
Fluttertoast.showToast(
msg: 'Toast 提示',
// 时间长短Toast.LENGTH_SHORT(2500ms)、Toast.LENGTH_LONG(3500ms)
toastLength: Toast.LENGTH_SHORT,
// 消息框弹出的位置 (上中下)ToastGravity.TOP、ToastGravity.CENTER、 ToastGravity.BOTTOM
gravity: ToastGravity.CENTER,
// 消息框持续的时间(目前的版本只有ios有效)
timeInSecForIos: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
网友评论