RegexRouter class abstract
Router with regex syntax.
For each path, you can use RegExp pattern. All named groups are passed
to pathArgs
parameter (see RegExpMatch). Moreover, there's an option to build
simple argument that matches [a-zA-Z0-9_\\\-\.,:;\+*^%\$@!]+
regex. To do so, just put a group name
straight after a colon (group name must fit [a-zA-Z0-9_-]+
pattern):
Both examples are equal:
"/:id": (context, args) => Page(args["id"])
"/(?<id>[a-zA-Z0-9_-]+)" => Page(args["id"])
To start using RegexRouter, create it's instance using RegexRouter.create factory method:
final router = RegexRouter.create({
"/": (context, _) => HomePage(),
"/second/:id/": (context, args) => AnotherPage(id: args["id"]),
"/withBody": (context, args) => PageWithBody(body: args.body),
});
And then attach it to your Material's app:
MaterialApp(
// ...
onGenerateRoute: router.generateRoute,
initialRoute: "/",
// ...
)
To navigate, just use a named route:
Navigator.of(context).pushNamed("/")
Navigator.of(context).pushNamed("/second/7")
Navigator.of(context).pushNamed("/withBody", arguments: {"key": "value"})
Constructors
-
RegexRouter.create(Map<
String, RouteBuilder> routeMap) -
A factory method to create RegexRouter instance with
routeMap
.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
generateRoute(
RouteSettings settings) → Route? - A function to be attached in MaterialApp.onGenerateRoute.
-
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