SafeRoute<TArgs, TResult> class

A strongly-typed route that holds information about a page and its argument/result types.

SafeRoute<TArgs, TResult> ensures that:

  • Arguments passed into the route are of type TArgs.
  • Results returned from the route are of type TResult.

This prevents runtime crashes due to invalid arguments or results.

Example:

final userRoute = SafeRoute<String, bool>(
  name: '/user',
  builder: (context, username) => UserPage(username: username),
);

// Navigate with arguments
final result = await Navigator.of(context).pushRoute(userRoute, "Alex");

// `result` is guaranteed to be a `bool`
Inheritance

Constructors

SafeRoute.new({required String name, required Widget builder(BuildContext, TArgs)})
Creates a new SafeRoute.

Properties

builder Widget Function(BuildContext, TArgs)
A function that builds the widget for this route.
final
fullPath String
The full path of this route, including all parent paths.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
name String
Route path fragment (relative to its parent).
finalinherited
parent RouteNode<Object?>?
Get parent route
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

materialPageRoute(TArgs args) Route<TResult>
Builds a MaterialPageRoute for this safe route.
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