Flutter 换屏回调

mar*_*uum 5 mobile flutter

I want to get a callback when the screen is changed, so I can stop my recurring request that runs on that specific screen. “dispose” is only called when Navigator.pop is used, but not when Navigator.push is called. Is there a way to detect that the screen is changed and not being shown at the moment?

tua*_* vu 9

在您的 MaterialApp 或 WidgetsApp 上注册一个 RouteObserver,并使您的有状态小部件成为 RouteAware。这里的示例代码:RouteObserver