regex_router 1.0.4 copy "regex_router: ^1.0.4" to clipboard
regex_router: ^1.0.4 copied to clipboard

outdated

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.

14
likes
30
points
34
downloads

Publisher

verified publisherjelenski.net

Weekly Downloads

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

License

MIT (license)

Dependencies

collection, flutter

More

Packages that depend on regex_router