Reputation: 411
Is there is a way to get names of the pushed routes from the navigation stack ?
Upvotes: 2
Views: 899
Reputation: 3087
Maybe NavigatorObserver can help to achieve what you want
MaterialApp(
navigatorObservers: [MyNavigatorObserver()],...)
class MyNavigatorObserver extends NavigatorObserver {
List<Route<dynamic>> routeStack = List();
void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
routeStack.add(route);
}
void didPop(Route<dynamic> route, Route<dynamic> previousRoute) {
routeStack.removeLast();
}
@override
void didRemove(Route route, Route previousRoute) {
routeStack.removeLast();
}
@override
void didReplace({Route newRoute, Route oldRoute}) {
routeStack.removeLast();
routeStack.add(newRoute);
}
}
Upvotes: 3