I'm trying to find a way to setup a global Navigation listener in the Root of my app (MaterialApp) which can allow me to track all navigation events including the actual route name (/home/page1 for ex.), navigation type etc.
I search something like:
MaterialApp(
initialRoute: '/',
onGenerateRoute: (RouteSettings settings) => route(settings),
onNavigationChange: (RouteType type, String currentRoute) {
// type can an enum be like: 'pop', 'push', 'replace' etc.
// currentRoute is the current route name defined in a pushNamed for example
}
),
Note: this code is non functional, only to illustrate what I want ;)
During my search, I found quite some solutions like RouteObserver, route_observer_mixin which are almost what I'm looking for but I need to wrap all my pages with a mixin... so no a global solution :/
Do you have any clues ?
Thanks in advance,
EDIT thanks to @pskink, see the solution below