Skip to main content
This class represents a route in the navigation system, containing path information, parameters, metadata, and optional grouping.

Properties

path
String
required
The path of this route.
label
String
The label of this route, used for named navigation.
queryParameters
Map<String, String>
default:"{}"
Query parameters for this route.
pathParameters
Map<String, String>
default:"{}"
Path parameters extracted from the route path.
metadata
Map<String, dynamic>?
Optional metadata associated with this route.
group
String?
Optional group name for grouping related routes.
cacheKey
String?
A unique cache key for this route, used to manage page caching.
uri
Uri
The URI representation of this route.
arguments
Object?
Optional route arguments (inherited from RouteSettings).
name
String?
The route name (inherited from RouteSettings).

Constructor

DefaultRoute({
  required String path,
  String label = '',
  Map<String, String> queryParameters = const {},
  Map<String, String> pathParameters = const {},
  Map<String, dynamic>? metadata = const {},
  String? group,
  String? cacheKey,
  Object? arguments
})
path
String
required
The route path.
label
String
default:"''"
Optional route label.
queryParameters
Map<String, String>
default:"{}"
Query parameters.
pathParameters
Map<String, String>
default:"{}"
Path parameters.
metadata
Map<String, dynamic>?
default:"{}"
Optional metadata.
group
String?
Optional group name.
cacheKey
String?
Optional cache key.
arguments
Object?
Optional route arguments.

Factory constructors

fromUrl

factory DefaultRoute.fromUrl(
  String url, {
  String label = '',
  String? group,
  Map<String, dynamic>? metadata,
  String? cacheKey
})
Creates a DefaultRoute from a URL string. Parses the URL and extracts path and query parameters.
url
String
required
The URL to parse.
label
String
default:"''"
Optional route label.
group
String?
Optional group name.
metadata
Map<String, dynamic>?
Optional metadata.
cacheKey
String?
Optional cache key.

fromUri

factory DefaultRoute.fromUri(
  Uri uri, {
  String label = '',
  String? group,
  Map<String, dynamic>? metadata,
  String? cacheKey
})
Creates a DefaultRoute from a Uri object. Extracts path and query parameters from the URI.
uri
Uri
required
The URI to parse.
label
String
default:"''"
Optional route label.
group
String?
Optional group name.
metadata
Map<String, dynamic>?
Optional metadata.
cacheKey
String?
Optional cache key.

Methods

copyWith

DefaultRoute copyWith({
  String? label,
  String? path,
  Map<String, String>? queryParameters,
  Map<String, String>? pathParameters,
  Map<String, dynamic>? metadata,
  String? group,
  String? cacheKey,
  Object? arguments
})
Creates a copy of this route with the given fields replaced. All parameters are optional. If not provided, the original value is used.

operator []

operator [](String key)
Accesses query parameters using the bracket operator. Returns the value of the query parameter with the given key, or null if the key doesn’t exist.

Example

// Create a route from a path
final route = DefaultRoute(
  path: '/home',
  label: 'home',
);

// Create a route from a URL
final route = DefaultRoute.fromUrl('/user/123?tab=profile');
print(route.path); // '/user/123'
print(route.queryParameters); // {'tab': 'profile'}

// Access query parameters
final tab = route['tab']; // 'profile'

// Copy with modifications
final newRoute = route.copyWith(
  queryParameters: {'tab': 'settings'},
);

Type definitions

PopUntilRouteFunction

typedef PopUntilRouteFunction = bool Function(DefaultRoute route)
Function type for determining when to stop popping routes. Used in popUntilRoute to determine which route to stop at. Return true to stop at the given route, false to continue popping.

SetMainRoutesCallback

typedef SetMainRoutesCallback = List<DefaultRoute> Function(
  List<DefaultRoute> controller
)
Function type for customizing the route stack. Allows modification of the route stack before it’s applied. The function receives the current route list and returns a modified list.

Build docs developers (and LLMs) love