This class represents a route in the navigation system, containing path information, parameters, metadata, and optional grouping.
Properties
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.
Optional metadata associated with this route.
Optional group name for grouping related routes.
A unique cache key for this route, used to manage page caching.
The URI representation of this route.
Optional route arguments (inherited from RouteSettings).
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
})
queryParameters
Map<String, String>
default:"{}"
Query parameters.
pathParameters
Map<String, String>
default:"{}"
Path parameters.
metadata
Map<String, dynamic>?
default:"{}"
Optional metadata.
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.
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.
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 []
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.