我有一个奇怪的问题,AlertDialog 在 flutter 中关闭对话框。我正在使用下面的代码 fragment 来关闭 flutter 文档中提到的对话框。
Navigator.of(dialogContext).pop();
但是显示它如何不起作用并使应用程序进入非 Activity 模式并变成黑屏窗口。为了让它再次工作,我必须终止应用程序并重新启动。
这是flutter中alertdialog的完整代码
Future<Null> _showDialogContactDial(context, Contact contactRecord) async {
return showDialog<Null>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext dialogContext) {
return new AlertDialog(
title: new Text('Confirm Number'),
content: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new TextFormField(
maxLines: 1,
decoration: new InputDecoration(hintText: 'Number'),
keyboardType: TextInputType.number,
autofocus: false,
initialValue: contactRecord.phoneNumber.number,
),
],
),
),
actions: <Widget>[
new FlatButton(
child: new Text(
'Call',
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.of(dialogContext).pop();
_launchURL(
context);
},
),
new FlatButton(
color: Colors.red,
child: new Text('Close', style: TextStyle(color: Colors.white)),
onPressed: () {
Navigator.of(dialogContext).pop();
},
),
],
);
},
);
}
我还注意到它适用于一个按钮“调用”而没有任何问题,但不适用于取消警报对话框,正如您在两个按钮操作的相同代码 fragment 中看到的那样。
帮助将不胜感激。
最佳答案
只需添加 rootNavigator:true
Navigator.of(dialogcon, rootNavigator: true).pop();
关于android - Flutter AlertDialog Navigator 弹出黑屏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53674433/