gpt4 book ai didi

flutter - 按下按钮时未显示警报对话框

转载 作者:行者123 更新时间:2023-12-03 04:21:29 25 4
gpt4 key购买 nike

警报对话框的类

class AlertWindow extends StatelessWidget {
final String title;

const AlertWindow({Key key, this.title}) : super(key: key);


@override
Widget build(BuildContext context) {

return Builder(
builder:(BuildContext context) {
return AlertDialog(
title: Text(this.title),
actions: <Widget>[
new FlatButton(
onPressed: (){
Navigator.of(context).pop();
},
child: new Text(
"OK"
)
),
],
);
}
);
}
}

像这样在 aysnc函数中调用了它
  Future<ParseUser> SignUP(username, pass, email) async {
var user = ParseUser(username, pass, email); // You can add columns to user object adding "..set(key,value)"
var result = await user.create();
if (result.success) {
setState(() {
_parseUser = user; // Keep the user
});
print(user.objectId);
new AlertWindow(
title: "Signup success " + user.objectId,
);
} else {
print(result.error.message);
new AlertWindow(
title: "Signup error " + result.error.message,
);
}
}

运行此命令后,我可以在控制台中看到 print语句,但是 AlertWindow没有显示。

我有一种预感,它可能与创建时未传递给 BuildContext的父 AlertDialog有关。

最佳答案

尝试使用函数而不是小部件
创建一个新的功能,返回 future

      Future<dynamic> _showDialog(BuildContext context){
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(this.title),
actions: <Widget>[
new FlatButton(
onPressed: (){
Navigator.of(context).pop();
},
child: new Text(
"OK"
)
),
],
);
}
);
}

关于flutter - 按下按钮时未显示警报对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62360768/

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