regex_router 1.0.3

Flutter Android iOS web

Router with regex support. Use names to provide arguments like in REST.

regex_router #

Material router with regex path support.

Usage #

Just define router instance and pass router.generateRoute to MaterialApp or any other Navigator.

final router = RegexRouter.create({
    "/": (context, _) => SamplePage(title: "BLoC showcase"),
    "/post/:id": (context, args) => PostPage(
        id: args["id"]), // Access path arguments with their names.
    "/post/:id/attachment/:attachmentId": (context, args) => PostAttachmentPage(
        id: args["id"],
        attachmentId: args["attachmentId"],
        body: args.body as Map<String, String>), // Access "object" arguments from `NavigatorState.pushNamed`.
});

return MaterialApp(
    onGenerateRoute: router.generateRoute,
    initialRoute: "/",
    title: 'Flutter Demo',
    theme: ThemeData(primarySwatch: Colors.blue),
);

// Somewhere inside `MaterialApp` container:

Navigator.of(context).pushNamed("/post/7"); // Navigate to path with argument.
Navigator.of(context).pushNamed("/post/7/attachment/8", argument: {"payload": "data"}); // Navigate to path with argument and body.

Samples #

You can experiment with a sample application hosted here: https://gitlab.com/marcin.jelenski/bloc-showcase

Also test directory contains all router use cases.

2
likes
110
pub points
45%
popularity

Publisher

jelenski.net

Router with regex support. Use names to provide arguments like in REST.

Repository (GitLab)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection, flutter

More

Packages that depend on regex_router