当 Widget 进入视图(未创建)时如何调用函数?

How to call a function when a Widget comes into view (not created)?

我需要在窗口小部件出现时刷新它的状态。例如,当我调用 Navigator.push(SomePage()); 然后按后退按钮时,不会创建较早的页面,因为它仍在树中,因此 initState() 不起作用。

基本上我需要在按下后退按钮后看到页面时刷新页面状态。

Navigator.push returns 一个 Future 以弹出推送路由时传递给 pop 方法的值完成。

因此,您可以await或使用.then完成pop之后的操作。

await Navigator.push(SomePage());
//Do some action

Navigator.push(SomePage()).then((_){
  //Do some action
});