Singleton manager for navigation operations. This class provides a centralized interface for navigation operations and manages the router delegate and route information parser.
Properties
Gets the singleton instance of NavigationManager. Throws an exception if init() has not been called.
The router delegate managing navigation.
routeInformationParser
DefaultRouteInformationParser
The route information parser.
Stream of current route changes.
The current route, or null if no route is active.
The current list of routes in the navigation stack.
Sets the callback for customizing the route stack.
setInitialRouteFunction
DefaultRoute Function(Uri initialRoute)?
Sets the function to determine the initial route from a URI.
setInitialRoutePathFunction
String Function(Uri initialRoute)?
Sets the function to determine the initial route path from a URI.
Methods
init
static NavigationManager init({
required BaseRouterDelegate mainRouterDelegate,
required DefaultRouteInformationParser routeInformationParser
})
Initializes the NavigationManager singleton. This must be called before using NavigationManager.instance.
mainRouterDelegate
BaseRouterDelegate
required
The router delegate to use.
routeInformationParser
DefaultRouteInformationParser
required
The route information parser to use.
Returns the initialized NavigationManager instance.
push
Future<dynamic> push(
String name, {
Map<String, String>? queryParameters,
Object? arguments,
Map<String, dynamic> data = const {},
Map<String, String> pathParameters = const {},
bool apply = true
})
Pushes a new route onto the navigation stack.
The route name or path to push.
Query parameters for the route.
Arguments to pass to the route.
data
Map<String, dynamic>
default:"{}"
Global data associated with the route.
pathParameters
Map<String, String>
default:"{}"
Path parameters for the route.
Whether to apply changes immediately.
pushRoute
Future<dynamic> pushRoute(DefaultRoute route, {bool apply = true})
Pushes a route object onto the navigation stack.
Whether to apply changes immediately.
pop
void pop([dynamic result, bool apply = true, bool all = false])
Pops the current route from the navigation stack.
Result to return to the previous route.
Whether to apply changes immediately.
Whether to pop all routes.
popUntil
void popUntil(
String name, {
bool apply = true,
bool all = false,
bool inclusive = false
})
Pops routes until the specified route is reached.
The route name to pop until.
Whether to apply changes immediately.
Whether to allow popping all routes.
Whether to include the target route in the pop.
popUntilRoute
void popUntilRoute(
PopUntilRouteFunction popUntilRouteFunction, {
bool apply = true,
bool all = false,
bool inclusive = false
})
Pops routes until the function returns true.
popUntilRouteFunction
PopUntilRouteFunction
required
Function that returns true to stop popping.
Whether to apply changes immediately.
Whether to allow popping all routes.
Whether to include the target route in the pop.
pushAndRemoveUntil
Future<dynamic> pushAndRemoveUntil(
String name,
String routeUntilName, {
Map<String, String>? queryParameters,
Object? arguments,
Map<String, dynamic> data = const {},
Map<String, String> pathParameters = const {},
bool apply = true,
bool inclusive = false
})
Pushes a route and removes routes until the specified route.
pushAndRemoveUntilRoute
Future<dynamic> pushAndRemoveUntilRoute(
DefaultRoute route,
PopUntilRouteFunction popUntilRouteFunction, {
bool apply = true,
bool inclusive = false
})
Pushes a route and removes routes until the function returns true.
remove
void remove(String name, {bool apply = true})
Removes a route from the stack by name.
removeRoute
void removeRoute(DefaultRoute route, {bool apply = true})
Removes a specific route from the stack.
pushReplacement
Future<dynamic> pushReplacement(
String name, {
Map<String, String>? queryParameters,
Object? arguments,
Map<String, dynamic> data = const {},
Map<String, String> pathParameters = const {},
dynamic result,
bool apply = true
})
Replaces the current route with a new one.
pushReplacementRoute
Future<dynamic> pushReplacementRoute(
DefaultRoute route,
[dynamic result, bool apply = true]
)
Replaces the current route with a route object.
removeBelow
void removeBelow(String name, {bool apply = true})
Removes the route below the specified route.
removeRouteBelow
void removeRouteBelow(DefaultRoute route, {bool apply = true})
Removes the route below the specified route object.
removeAbove
void removeAbove(String name, {bool apply = true})
Removes the route above the specified route.
removeRouteAbove
void removeRouteAbove(DefaultRoute route, {bool apply = true})
Removes the route above the specified route object.
removeGroup
void removeGroup(String name, {bool apply = true, bool all = false})
Removes all routes with the specified group name.
replace
void replace(
String oldName, {
String? newName,
DefaultRoute? newRoute,
Map<String, dynamic>? data,
bool apply = true
})
Replaces a route with a new route.
replaceRoute
void replaceRoute(DefaultRoute oldRoute, DefaultRoute newRoute, {bool apply = true})
Replaces a route object with another route object.
replaceBelow
void replaceBelow(String anchorName, String name, {bool apply = true})
Replaces the route below the anchor route.
replaceRouteBelow
void replaceRouteBelow(DefaultRoute anchorRoute, DefaultRoute newRoute, {bool apply = true})
Replaces the route below the anchor route object.
set
void set(List<String> names, {bool apply = true})
Sets the entire navigation stack to the specified routes.
setRoutes
void setRoutes(List<DefaultRoute> routes, {bool apply = true})
Sets the entire navigation stack to the specified route objects.
setBackstack
void setBackstack(List<String> names, {bool apply = true})
Sets the backstack while preserving the current route.
setBackstackRoutes
void setBackstackRoutes(List<DefaultRoute> routes, {bool apply = true})
Sets the backstack with route objects while preserving the current route.
setOverride
void setOverride(Page Function(String name) pageBuilder, {bool apply = true})
Sets a page override that replaces the normal navigation stack.
removeOverride
void removeOverride({bool apply = true})
Removes the page override.
setQueryParameters
void setQueryParameters(Map<String, String> queryParameters, {bool apply = true})
Sets query parameters on the current route.
setOverlay
void setOverlay(Page Function(String name) pageBuilder, {bool apply = true})
Sets a page overlay on top of the navigation stack.
removeOverlay
void removeOverlay({bool apply = true})
Removes the page overlay.
navigate
void navigate(BuildContext context, Function function)
Executes navigation changes within a Router.navigate context.
neglect
void neglect(BuildContext context, Function function)
Executes navigation changes within a Router.neglect context.
apply
Applies pending navigation changes.
clear
Clears the navigation stack.
pauseNavigation
void pauseNavigation({Page Function(String name)? pageBuilder})
Pauses and defers navigation. Displays a CupertinoActivityIndicator page until resumeNavigation is called. Useful for forcing delayed navigation until an async operation completes.
pageBuilder
Page Function(String name)?
Optional custom loading page builder.
resumeNavigation
Resumes navigation and removes page overrides. Calls removeOverride under the hood. Has no effect if pauseNavigation has not been called.
nested
List<Widget> nested({
required BuildContext context,
required List<NavigationData> routes,
bool removeDuplicates = true
})
Returns a list of widgets for building nested navigation. Build tabbed navigation and nested page navigation flows.
routes
List<NavigationData>
required
List of NavigationData defining the nested routes.
Whether to remove duplicate widgets.