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

时间:2018-07-27 13:02:32

标签: dart flutter

考虑我的情况

//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
});

我该如何实现?

2 个答案:

答案 0 :(得分:2)

我认为这应该很简单 Navigator.pop(context);

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

我猜这两种方法在同一build()中。因此它们具有相同的BuildContext,因此上面的方法应该有效。

答案 1 :(得分:0)

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

  Navigator.of(context).pop();