我想在打开应用程序之前显示一个确认警报对话框,有人可以告诉我如何在颤振中实现这一点吗?
showDialog() 方法需要一个上下文,因此我应该将它与 buildContext 放在某个地方,我假设在应用程序的构建方法中,但是如何在屏幕上构建实际布局之前触发对话框?
下面的代码有效,我想这就是答案
@override
Widget build(BuildContext context) {
Future.delayed(Duration.zero, () => showAlert(context));
return new WhateverLayoutYouWantToBeDisplayed();
}
void showAlert(BuildContext context) {
showDialog(
child: new WhateverCustomDialogYouHave(),
context: context);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句