Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter screen change callback

Tags:

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?

like image 704
koraxis Avatar asked Jul 11 '18 10:07

koraxis


People also ask

What is MaterialPageRoute in Flutter?

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.

What is Pushreplacement in Flutter?

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.


1 Answers

Register a RouteObserver on your MaterialApp or WidgetsApp and make your stateful widget a RouteAware. Sample code here: RouteObserver

like image 168
tuan vu Avatar answered Sep 28 '22 17:09

tuan vu