[英]Dialog box is not closing flutter
Here's my Alert dialog code: I've added Navigator.pop(context);这是我的警报对话框代码:我添加了 Navigator.pop(context); in the tapped method call.在点击的方法调用中。 But it's not closing.但它并没有关闭。
showLoginDialog(BuildContext context,
{TextEditingController usernameController,
TextEditingController loginController}) {
var textController = new TextEditingController();
var nameTextController = new TextEditingController();
String dateToPost;
Alert(
context: context,
title: "Add Profile",
content: Column(
children: <Widget>[
TextField(
controller: nameTextController,
decoration: InputDecoration(
labelText: 'Name',
),
),
TextField(
controller: textController,
onTap: () async {
DateTime date = DateTime(1900);
//FocusScope.of(context).requestFocus(new FocusNode());
date = await showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(1900),
lastDate: DateTime.now());
var formatter = new DateFormat('dd MMM yyyy');
var formatterToPost = new DateFormat('yyyy-MM-dd');
String formatted = formatter.format(date);
dateToPost = formatterToPost.format(date);
print(formatted);
textController.text = formatted;
},
decoration: InputDecoration(
labelText: 'Birth Date',
),
),
],
),
buttons: [
DialogButton(
onPressed: () {
Navigator.pop(context);
_saveData(textController.text, nameTextController.text,
dateToPost);
},
child: Text(
"Add",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
} }
Also, is shows error on second time click: The method 'call' was called on null.此外,在第二次单击时显示错误:在 null 上调用了方法“调用”。 Receiver: null Tried calling: call()接收者:空尝试调用:call()
我已经解决了这个问题
Navigator.of(context, rootNavigator: true).pop();
You should save the data before you close the application.您应该在关闭应用程序之前保存数据。
And instead of Navigator.pop(context)
do Navigator.of(context).pop(true)
而不是Navigator.pop(context)
做Navigator.of(context).pop(true)
onPressed: () {
_saveData(textController.text, nameTextController.text,
dateToPost);
Navigator.of(context).pop(true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.