在Flutter中关闭showDialog之后如何运行代码? [英] How run code after showDialog is dismissed in Flutter?

查看:90
本文介绍了在Flutter中关闭showDialog之后如何运行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

showDialog()被解散/处置后如何更新主页?似乎没有 onDispose()函数。

How to update the Homepage just after the showDialog() is dismissed/disposed? Doesn't seem like it has an onDispose() function.

找到了另一个可能的答案: WillPopScope 可以帮助检测是否按下了后退按钮。

Found another possible Answer : The WillPopScope can help detect if the back button is pressed.

将在中使用的小部件showDialog ,在其构建函数中,小部件可以包装在中,返回新的WillPopScope(child:______,onWillPop:_______); 可以运行代码在 onWillPop 函数中。这样可以更新下面的主页。

The widget that will be used in the showDialog, in its build function the widget can be wrapped in return new WillPopScope(child: ______, onWillPop: _______); The code can be run in the onWillPop function. This can update the Homepage below.

推荐答案

只需使用await,然后, then块中的代码将在对话框之后运行被关闭

Simply use await and then, the code in "then" block will run after the dialog is dismissed

await showDialog(
       //Your Dialog Code
).then((val){
    Navigator.pop(_context);
});

这篇关于在Flutter中关闭showDialog之后如何运行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆