AppNavigator class
Centralized navigation service that uses EventBus for decoupled navigation.
This allows plugins to intercept and handle navigation events (like tab switching) while falling back to standard Flutter Navigator if no listeners handle the event.
Usage:
// Standard navigation (works exactly like Navigator.pushNamed)
AppNavigator.pushNamed(context, '/product', arguments: {'id': '123'});
// Tab switching (if BottomTabbedHomePlugin is active, it intercepts)
AppNavigator.switchToTab(context, 'cart');
// Pop (respects custom handlers)
AppNavigator.pop(context);
For Plugin Authors:
Listen to navigation events in your plugin:
AppNavigator.eventBus.on('navigation.switch_to_tab', (event) {
final tabId = event.data['tabId'] as String?;
final context = event.data['context'] as BuildContext;
final markHandled = event.data['_markHandled'] as Function;
// Switch to tab...
markHandled(null);
});
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
canPop<
T extends Object?> (BuildContext context, [T? result]) → bool -
pop<
T extends Object?> (BuildContext context, [T? result]) → void - Pop the current route.
-
push<
T extends Object?> (BuildContext context, Route< T> route) → Future<T?> - Push a route.
-
pushNamed<
T extends Object?> (BuildContext context, String routeName, {Object? arguments}) → Future< T?> - Push a named route.
-
pushReplacementNamed<
T extends Object?, TO extends Object?> (BuildContext context, String routeName, {TO? result, Object? arguments}) → Future< T?> -
setEventBus(
EventBus eventBus) → void - Wire the scoped EventBus from MooseAppContext.
-
switchToTab(
BuildContext context, String tabId) → Future< void> - Switch to a tab by ID.
-
switchToTabIndex(
BuildContext context, int index) → Future< void> - Switch to a tab by index.