Skip to main content
Router delegate classes that manage navigation state and build the Navigator widget.

BaseRouterDelegate

Base class for router delegates. The RouteDelegate defines application specific behaviors of how the router learns about changes in the application state and how it responds to them. This abstract class provides the core navigation functionality and should be extended to create custom router delegates.

Properties

navigatorKey
GlobalKey<NavigatorState>
Global key for the Navigator widget. Persists the navigator across rebuilds.
routes
List<DefaultRoute>
The current list of routes in the navigation stack.
canPop
bool
Whether the current route can be popped. Returns false if canPop was explicitly set to false, or if there are no routes in the stack.
currentConfiguration
DefaultRoute?
Returns the last route in the stack, or null if the stack is empty. Helps complete the browser history and enables browser back and forward buttons.
getCurrentRoute
Stream<DefaultRoute>
Stream of current route changes. Listen to this stream to be notified when the current route changes.
globalData
Map<String, dynamic>
Global data map for storing route-specific data.
navigationDataRoutes
List<NavigationData>
List of navigation data routes. This must be set by the implementing class.
pageOverride
Page Function(String name)?
Optional page override function. If set, this function is called to build a page that overrides the normal navigation stack. Useful for loading screens.
pageOverlay
Page Function(String name)?
Optional page overlay function. If set, this function is called to build a page that overlays the normal navigation stack. Useful for lock screens.
setMainRoutes
SetMainRoutesCallback?
Exposes the routes history to the implementation to allow modifying the navigation stack based on app state.
onUnknownRoute
OnUnknownRoute?
Unknown route generation function.
debugLog
bool
Whether to enable debug logging for navigation operations. When enabled, navigation operations will print debug messages to help with troubleshooting.

Methods

BaseRouterDelegate implements all methods from NavigationInterface. See NavigationManager for the complete list of navigation methods including:
  • push, pushRoute
  • pop, popUntil, popUntilRoute
  • pushAndRemoveUntil, pushAndRemoveUntilRoute
  • remove, removeRoute
  • pushReplacement, pushReplacementRoute
  • removeBelow, removeRouteBelow
  • removeAbove, removeRouteAbove
  • removeGroup
  • replace, replaceRoute
  • replaceBelow, replaceRouteBelow
  • set, setRoutes
  • setBackstack, setBackstackRoutes
  • setOverride, removeOverride
  • setOverlay, removeOverlay
  • setQueryParameters
  • navigate, neglect
  • apply, clear

DefaultRouterDelegate

Default implementation of BaseRouterDelegate. This class provides a complete router delegate implementation with support for deeplinks, custom page builders, and navigation observers.

Constructor

DefaultRouterDelegate({
  required List<NavigationData> navigationDataRoutes,
  bool debugLog = false,
  OnUnknownRoute? onUnknownRoute,
  CustomPageBuilder? pageBuilder,
  MigrationPageBuilder? migrationPageBuilder,
  List<NavigatorObserver> observers = const [],
  List<DeeplinkDestination> deeplinkDestinations = const [],
  bool? Function(Uri uri)? customDeeplinkHandler,
  bool authenticated = true,
  List<String> excludeDeeplinkNavigationPages = const [],
  PopPageCallback? onPopPage
})
navigationDataRoutes
List<NavigationData>
required
List of navigation routes.
debugLog
bool
default:"false"
Whether to enable debug logging.
onUnknownRoute
OnUnknownRoute?
Handler for unknown routes.
pageBuilder
CustomPageBuilder?
Optional custom page builder for all routes.
migrationPageBuilder
MigrationPageBuilder?
Optional migration page builder for legacy route support.
observers
List<NavigatorObserver>
default:"[]"
List of navigation observers to attach to the Navigator.
List of deeplink destinations to handle.
Optional custom deeplink handler function. If provided, this function is called for all incoming deeplinks. Return true if the deeplink was handled, false otherwise.
authenticated
bool
default:"true"
Whether the user is currently authenticated. Used to determine if authenticated deeplinks can be opened.
List of route names/paths to exclude from deeplink navigation.
onPopPage
PopPageCallback?
Optional callback for handling pop page events.

Properties

pageBuilder
CustomPageBuilder?
Optional custom page builder for all routes.
migrationPageBuilder
MigrationPageBuilder?
Optional migration page builder for legacy route support.
observers
List<NavigatorObserver>
List of navigation observers to attach to the Navigator.
List of deeplink destinations to handle.
Optional custom deeplink handler function.
authenticated
bool
Whether the user is currently authenticated.
List of route names/paths to exclude from deeplink navigation.
onPopPage
PopPageCallback?
Optional callback for handling pop page events.

Methods

build

Widget build(BuildContext context)
Builds the Navigator widget with the current pages.

setNewRoutePath

Future<void> setNewRoutePath(DefaultRoute configuration)
Handles new route paths, including deeplink processing.

Example

// Create a router delegate
final routerDelegate = DefaultRouterDelegate(
  navigationDataRoutes: [
    NavigationData(
      label: 'home',
      url: '/home',
      builder: (context, route, data) => HomePage(),
    ),
    NavigationData(
      label: 'profile',
      url: '/profile',
      builder: (context, route, data) => ProfilePage(),
    ),
  ],
  debugLog: true,
  onUnknownRoute: (route) => MaterialPage(
    child: NotFoundPage(),
  ),
);

// Use in MaterialApp.router
MaterialApp.router(
  routerDelegate: routerDelegate,
  routeInformationParser: routeInformationParser,
);

Build docs developers (and LLMs) love