ZenRouteObserver class
Navigator observer that automatically disposes controllers when routes are popped and allows for custom route change callbacks
Features:
- Automatic controller disposal when routes are removed
- Route-to-controller mapping with scope support
- Tagged controller support
- Custom route change callbacks
- Performance metrics tracking
- Production-safe logging
Usage:
final routeObserver = ZenRouteObserver(
onRouteChanged: (route, previousRoute) {
print('Route changed to: ${route?.settings.name}');
},
);
// Register controllers for routes
routeObserver.registerForRoute('/home', [HomeController]);
routeObserver.registerTaggedForRoute('/profile', ['profile-controller']);
MaterialApp(
navigatorObservers: [routeObserver],
...
)
- Inheritance
-
- Object
- NavigatorObserver
- ZenRouteObserver
Constructors
- ZenRouteObserver({void onRouteChanged(Route? route, Route? previousRoute)?})
- Creates a ZenRouteObserver
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
The navigator that the observer is observing, if any.
no setterinherited
- onRouteChanged → void Function(Route? route, Route? previousRoute)?
-
Callback for when routes change
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clearAllRoutes(
) → void - Clear all route registrations
-
didChangeTop(
Route topRoute, Route? previousTopRoute) → void -
The top most route has changed.
inherited
-
didPop(
Route route, Route? previousRoute) → void -
The Navigator popped
route.override -
didPush(
Route route, Route? previousRoute) → void -
The Navigator pushed
route.override -
didRemove(
Route route, Route? previousRoute) → void -
The Navigator removed
route.override -
didReplace(
{Route? newRoute, Route? oldRoute}) → void -
The Navigator replaced
oldRoutewithnewRoute.override -
didStartUserGesture(
Route route, Route? previousRoute) → void -
The Navigator's routes are being moved by a user gesture.
override
-
didStopUserGesture(
) → void -
User gesture is no longer controlling the Navigator.
override
-
getDebugInfo(
) → Map< String, dynamic> - Get debug information about registered routes
-
getRegisteredRoutes(
) → Set< String> - Get all registered route names
-
getScopeForRoute(
String routeName) → ZenScope? - Get the scope associated with a route (if any)
-
hasControllersForRoute(
String routeName) → bool - Check if a route has registered controllers
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerForRoute(
String routeName, List< Type> controllerTypes, {ZenScope? scope}) → void - Register controllers for a specific route
-
registerTaggedForRoute(
String routeName, List< String> controllerTags, {ZenScope? scope}) → void - Register tagged controllers for a specific route
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited