【问题标题】:How to pop an alert dialog on Flutter from outside the builder如何从构建器外部在 Flutter 上弹出警报对话框
【发布时间】:2018-07-27 13:02:31
【问题描述】:

考虑我的情况

//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


    【解决方案1】:

    我觉得应该很简单 Navigator.pop(context);

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

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

    【讨论】:

      【解决方案2】:

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

        Navigator.of(context).pop();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-04
        • 2021-07-24
        • 2020-04-26
        • 2018-05-14
        • 1970-01-01
        • 2020-10-01
        相关资源
        最近更新 更多