show static method
void
show(
- String message, {
- String title = "提示",
- ContextCallback? okCallback,
- VoidCallback? cancelCallback,
- bool cancelable = false,
Implementation
static void show(String message, {String title="提示", ContextCallback? okCallback, VoidCallback? cancelCallback, bool cancelable = false}) {
final context = _instance!.navigatorKey.currentState!.overlay!.context;
List<Widget> actions = [];
if(okCallback != null) {
actions.add(FlatButton(
onPressed: () {
Navigator.of(context).pop();
okCallback(context);
},
child: Text("确定")));
}
if(cancelCallback != null) {
actions.add(FlatButton(onPressed: () {
Navigator.of(context).pop();
cancelCallback();
}, child: Text("取消")));
}
final dialog = AlertDialog(
title: Text(title),
content: Text(message),
actions: actions,
);
showDialog(context: context, barrierDismissible: cancelable, builder: (x) {
return WillPopScope(
onWillPop: () async => false,//关键代码
child: dialog,
);
});
}