如何从构建器外部在Flutter上弹出警报对话框

问题描述 投票:0回答:2

考虑我的情景

//Show the progress indicator inside an alert to block the user
showAlertProgressIndicator(); 

// Get the data
await DataManager.get().getDummyData().then((value){
      // After data acquisition pop the alertProgressIndicator
});

我怎样才能做到这一点?

dart flutter
2个回答
3
投票

我认为它应该是简单的Navigator.pop(context);

void closeAlert() {
  Navigator.pop(context);//it will close last route in your navigator
}

我猜这两种方法在同一个build()。所以他们有相同的BuildContext,所以上面应该工作。


0
投票

我创建了一个与这种情况相关的示例应用程序。它在这里https://github.com/Yahhi/flutter_dialog_test上下文相同,并且在定时器事件5秒后对话框消失。

  Navigator.of(context).pop();
© www.soinside.com 2019 - 2024. All rights reserved.