[英]How to load dialog box automatically and dismiss in flutter?
I used Future.delayed(Duration.zero, () => welcomeDialogBoxx(context));
我使用了Future.delayed(Duration.zero, () => welcomeDialogBoxx(context));
in build, a method to load dialog box automatically but there is an issue with it, whenever I navigate through another screen the dialog box further open on that screen. 在构建中,这是一种自动加载对话框的方法,但是存在问题,每当我浏览另一个屏幕时,对话框都会在该屏幕上进一步打开。 Dunno why it is loading further after got dismissed. 邓诺(Dunno)被解雇后,为什么还要继续加载。
here is the method the defined for the dialog box 这是为对话框定义的方法
welcomeDialogBoxx(BuildContext context) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
.....
);
});
}
This should open your dialog only once. 这应该只打开一次对话框。 Remove the Future from your Build method and add this code to your initState: 从您的Build方法中删除Future并将以下代码添加到您的initState中:
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => welcomeDialogBox(context));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.