gpt4 book ai didi

flutter - 对话框没有关闭 flutter

转载 作者:行者123 更新时间:2023-12-05 01:13:24 25 4
gpt4 key购买 nike

这是我的警报对话框代码:我添加了 Navigator.pop(context);在轻敲的方法调用中。但它没有关闭。

 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();

}

另外,在第二次点击时显示错误:方法“调用”在 null 上被调用。接收方:空尝试调用:call()

最佳答案

我已经用

解决了这个问题
Navigator.of(context, rootNavigator: true).pop();

关于flutter - 对话框没有关闭 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60279546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com