在Flutter中关闭showDialog之后如何运行代码? [英] How to run code after showDialog is dismissed in Flutter?
问题描述
在关闭/处理了 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
.对话框关闭后,将运行 then
块中的代码.
Simply use await
or then
. the code in then
block will be run after the dialog is dismissed.
showDialog(
// Your Dialog Code
).then((val){
Navigator.pop(_context);
});
这篇关于在Flutter中关闭showDialog之后如何运行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!