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?
MaterialPageRoute<T> class Null safety. A modal route that replaces the entire screen with a platform-adaptive transition. For Android, the entrance transition for the page zooms in and fades in while the exiting page zooms out and fades out. The exit transition is similar, but in reverse.
Replace the current route of the navigator that most tightly encloses the given context by pushing the given route and then disposing the previous route once the new route has finished animating in.
Register a RouteObserver on your MaterialApp or WidgetsApp and make your stateful widget a RouteAware. Sample code here: RouteObserver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With