AlterDialog 提示弹窗
_alterFun() async{
var result = await showDialog(
barrierDismissible:false,// 禁用点击空白处退出
context:context,
builder:(context){
return AlterDialog(
title:const Text("提示信息"),
content:Text("确认删除吗"),
actions:[
TextButton(
child:Text("取消"),
onPressed:(){
Navigator.pop(context,"取消") // 消除弹窗
}
),
TextButton(
child:Text("ok"),
onPressed:(){
Navigator.pop(context,"ok")
}
)
]
)
}
);
print(result)
}
待选项的组件 SimpleDialog、SimpleDialogOption
_simpleDialog() async {
var result = await showDialog(
barrierDismissible: true, //表示点击灰色背景的时候是否消失弹出框
context: context,
builder: (context) {
return SimpleDialog(
title: const Text("请选择内容"),
children: <Widget>[
SimpleDialogOption(
child: const Text("Option A"),
onPressed: () {
print("Option A");
Navigator.pop(context, "A");
},
),
const Divider(),
SimpleDialogOption(
child: const Text("Option B"),
onPressed: () {
print("Option B");
Navigator.pop(context, "B");
},
),
const Divider(),
SimpleDialogOption(
child: const Text("Option C"),
onPressed: () {
print("Option C");
Navigator.pop(context, "C");
},
),
],
);
});
print(result);
}
底部弹出层 showModalBottomSheet
_modelBottomSheet() async {
var result = await showModalBottomSheet(
context: context,
builder: (context) {
return SizedBox(
height: 220,
child: Column(
chilren:[
ListTile(
title: const Text("分享 A"),
onTap: () {
Navigator.pop(context, "分享 A");
},
),
const Divider(),
ListTile(
title: const Text("分享 B"),
onTap: () {
Navigator.pop(context, "分享 B");
},
),
const Divider(),
]
)
)
}
);
print(result)
}
自定义弹出层
String title;
String content;
Function()? onClosed;
MyDialog({Key? key, required this.title,required this.onClosed,this.content=""}) : super(key: key);
Material(
type:MateralType.transparency,// 设置透明背景
child:Inkwell(
onTap:onClosed,
child:Text("$title")
)
)
使用
void _myDialog() async {
await showDialog(
barrierDismissible: true, //表示点击灰色背景的时候是否消失弹出框
context: context,
builder: (context) {
return MyDialog(
title: '标题',
onClosed: () {
print("关闭");
Navigator.of(context).pop();
},
content: "我是一个内容");
}
);
}
toast 组件
第三方模块
fluttertoast: ^8.0.9
import 'package:fluttertoast/fluttertoast.dart';
Fluttertoast.showToast(
msg: "提示信息",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);