【发布时间】:2019-05-09 12:13:36
【问题描述】:
我有一个奇怪的问题,AlertDialog 在颤动中关闭对话框。我正在使用下面的代码 sn-p 来关闭颤振文档中提到的对话框。
Navigator.of(dialogContext).pop();
但显示它如何不起作用并使应用程序进入非活动模式并变成黑屏窗口。为了让它再次工作,我必须终止应用程序并重新启动。
这里是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();
},
),
],
);
},
);
}
我还注意到它适用于一个按钮“呼叫”而没有任何问题,但不适用于取消警报对话框,正如您在两个按钮操作中的相同代码 sn-p 中看到的那样。
【问题讨论】:
-
添加截图供参考
-
这里的问题不是 AlertDialogBox - 它与调用它的父小部件有关。你的代码工作正常。两者都适用于呼叫和关闭操作小部件。
标签: android mobile dart flutter flutter-layout