route_pattern_generator 0.1.0 copy "route_pattern_generator: ^0.1.0" to clipboard
route_pattern_generator: ^0.1.0 copied to clipboard

outdated

A Dart static code generator that produces matchers and builders from route uri patterns.

route_pattern_bloc_generator #

A Dart static code generator that produces matchers and builders from route URI patterns.

Quickstart #

Define your patterns as constant strings annoted with @route.

import 'package:route_pattern/route_pattern.dart';

part 'routes.g.dart';

@route
const home = "/?tab";

@route
const article = "/article/:id";

Each constant will generate a Route with a build and match method, and a corresponding Argument class (an example of the generate sources is available in the sample).

final route = HomeRoute();

final path = route.build(HomeRouteArguments(tab: "users"));
expect(path, "/?tab=users");

final match = route.match("/?tab=users");
expect(match.isSuccess, true);
expect(match.arguments.tab, '12345');

final route = ArticleRoute();

final path = route.build(ArticleRouteArguments(id: "12345"));
expect(path, "/article/12345");

final match = route.match("/article/12345");
expect(match.isSuccess, true);
expect(match.arguments.id, '12345');

How to use #

Install #

There are a few separate packages you need to install:

dependencies:
  route_pattern:

dev_dependencies:
  route_pattern_generator: 
  build_runner: 

Pattern format #

A route pattern is composed of static segments separated with /, required parameters as dynamic segments (starting with :), and optional parameters as query parameters (starting with ? and separated by &).

Example

/article/:id/details?tab&scroll

  • article : static segment
  • id : required dynamic segment
  • details : static segment
  • tab : optionnal query parameter
  • scroll : optionnal query parameter

This example will match those URIs :

  • /article/26436/details
  • /article/DH4H5JH5/details?tab=1
  • /article/°098904/details?tab=first&scroll=8

Run the generator #

To run the generator, you must use build_runner cli:

flutter pub pub run build_runner watch
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A Dart static code generator that produces matchers and builders from route uri patterns.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, build, build_config, code_builder, dart_style, path, recase, route_pattern, source_gen

More

Packages that depend on route_pattern_generator