从导航堆栈弹出后打开屏幕时调用哪个函数?

问题描述 投票:0回答:2

我有2个屏幕 - 屏幕A和屏幕B.我从屏幕A导航到屏幕B.我想通过从导航堆栈中弹出屏幕B来回到屏幕A时采取一些特殊操作。我知道我可以使用didUpdateWidge,但我无法找到一种有效的方法。在这里使用Inherited Widget是正确的方法吗?

flutter navigation
2个回答
1
投票

Navigator.push[Named]返回一个Future,当屏幕B弹出时完成。因此,在弹出后将要执行的代码添加到then

  Navigator.pushNamed(context, '/someRoute').then((_) {/* do stuff here */});

0
投票

尝试使用WillPopScope。此小部件允许按下按钮按下。

© www.soinside.com 2019 - 2024. All rights reserved.