【发布时间】:2021-02-04 10:19:09
【问题描述】:
我已经通过这种方式实现了应用退出确认:
return WillPopScope(
onWillPop: _promptExit,
child: Container() /*Remaining window layout*/
_promptExit 函数显示对话框以确认退出:
return showDialog(
context: context,
builder: (context) => new AlertDialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(20.0))),
title: new Text(Strings.prompt_exit_title),
content: new Text(Strings.prompt_exit_content),
actions: <Widget>[
FlatButton(
child: new Text(Strings.no),
onPressed: () => Navigator.of(context).pop(false),
),
SizedBox(height: 16),
FlatButton(
child: new Text(Strings.yes),
onPressed: () => Navigator.of(context).pop(true),
),
],
),
) ??
false;
它有效,但我想使用自定义对话框而不是标准对话框:https://github.com/marcos930807/awesomeDialogs
它在内部调用showDialog,所以我尝试了这种方式:
AwesomeDialog dlg = AwesomeDialog(
context: context,
dialogType: DialogType.QUESTION,
animType: AnimType.BOTTOMSLIDE,
title: Strings.prompt_exit_title,
desc: Strings.prompt_exit_content,
dismissOnBackKeyPress: false,
useRootNavigator: true,
btnCancelOnPress: () { Navigator.of(context).pop(false);},
btnOkOnPress: () { Navigator.of(context).pop(true);},
btnOkText: Strings.yes,
btnCancelText: Strings.no
);
return dlg.show() ?? false;
但我不能这样弹出,我正在黑屏。我该怎么办?
【问题讨论】: