Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observer for Navigator route changes in Flutter

Tags:

flutter

dart

Is there a way to listen to route changes of the Navigator in Flutter? Basically, I'd like to be notified when a route is pushed or popped, and have the current route on display on screen be returned from the notification

like image 693
user3217522 Avatar asked Aug 07 '17 07:08

user3217522


People also ask

How do you use Route observer in Flutter?

RouteObserver<R extends Route> class Null safety A Navigator observer that notifies RouteAwares of changes to the state of their Route. RouteObserver informs subscribers whenever a route of type R is pushed on top of their own route of type R or popped from it.

How do you get navigation stack in Flutter?

Flutter Navigator class The Navigator class provides all the navigation capabilities in a Flutter app. Navigator provides methods to mutate the stack by a push to stack or by popping from the stack. The Navigator. push method is for navigating to a newer page and Navigator.


2 Answers

Building on navigator observers, you can also use RouteObserver and RouteAware.

like image 122
Thibault Avatar answered Sep 23 '22 18:09

Thibault


Navigator has observers. You can implement NavigatorObserver and receive notifications with details.

like image 37
German Saprykin Avatar answered Sep 22 '22 18:09

German Saprykin