{"id":16583804,"url":"https://github.com/aloisdeniel/route_pattern_generator","last_synced_at":"2025-08-22T00:34:12.848Z","repository":{"id":56838352,"uuid":"187227839","full_name":"aloisdeniel/route_pattern_generator","owner":"aloisdeniel","description":"A Dart static code generator that produces matchers and builders from route uri patterns.","archived":false,"fork":false,"pushed_at":"2021-05-06T18:05:39.000Z","size":36,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-12T22:43:20.046Z","etag":null,"topics":["dart","flutter","match","pattern","routing","uri"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aloisdeniel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-17T14:10:44.000Z","updated_at":"2024-06-20T14:28:16.000Z","dependencies_parsed_at":"2022-09-10T00:41:35.137Z","dependency_job_id":null,"html_url":"https://github.com/aloisdeniel/route_pattern_generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Froute_pattern_generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Froute_pattern_generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Froute_pattern_generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Froute_pattern_generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aloisdeniel","download_url":"https://codeload.github.com/aloisdeniel/route_pattern_generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221815310,"owners_count":16885160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","match","pattern","routing","uri"],"created_at":"2024-10-11T22:43:14.666Z","updated_at":"2024-10-28T10:10:08.222Z","avatar_url":"https://github.com/aloisdeniel.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# route_pattern_generator\n\nA Dart static code generator that produces matchers and builders from route URI patterns.\n\n## Quickstart\n\nDefine your patterns as constant strings annoted with `@route`.\n\n```dart\nimport 'package:route_pattern/route_pattern.dart';\nimport 'package:flutter/widgets.dart';\n\npart 'routes.g.dart';\n\n@RoutePattern(\"/?tab\u0026[int]scroll\")\nRoute home(RouteSettings settings, HomeRouteArguments arguments) {\n    // returns a Route\n}\n\n@RoutePattern(\"/article/:[int]id\")\nRoute article(RouteSettings settings, ArticleRouteArguments arguments) {\n    // returns a Route\n}\n```\n\nEach constant will generate a `Route` with a `build` and `match` method, and a associated `Argument` class ([an example of the generate sources is available in the sample](sample/lib/routes.g.dart)).\n\n```dart\n// Build specific routes\nfinal path = Routes.home.build(HomeRouteArguments(tab: \"users\"));\nexpect(path, \"/?tab=users\");\n\nfinal path = Routes.article.build(ArticleRouteArguments(id: \"12345\"));\nexpect(path, \"/article/12345\");\n\n// Match specific routes\nfinal match = Routes.home.match(\"/?tab=users\");\nexpect(match.isSuccess, true);\nexpect(match.arguments.tab, 'users');\n\nfinal match = Routes.article.match(\"/article/12345\");\nexpect(match.isSuccess, true);\nexpect(match.arguments.id, '12345');\n\n// Or get the first matching route\nfinal match = Routes.match(\"/article/12345\");\nif(match is MatchResult\u003cArticleRouteArguments\u003e) {\n    expect(match.arguments.id, '12345');\n}\n```\n\nA `Routes.onGenerateRoute` method is also generated to use in your app or navigator. It will match the first route which settings name matches a pattern and call your declared function with corresponding arguments.\n\n```dart\nimport 'package:sample/routes.dart';\nimport 'package:flutter/material.dart';\n\nclass ExampleApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return MaterialApp(\n      onGenerateRoute: Routes.onGenerateRoute,\n      // ...\n    );\n  }\n}\n```\n\nTo navigate to a given route, a `Routes.push` method is also available :\n\n```dart\nawait Routes.push(context, ArticleRouteArguments(id: '12345'));\n```\n\n## How to use\n\n### Install\n\nThere are a few separate packages you need to install:\n\n```yaml\ndependencies:\n  route_pattern:\n\ndev_dependencies:\n  route_pattern_generator: \n  build_runner: \n```\n\n### Pattern format\n\nA 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 `\u0026`).\n\n### Typing parameters\n\nBy default, arguments are of type `String`, but a custom type surrounded with `[` and `]` can be added at the beginning of a required or optional parameter. This type must have static `T parse(String value)` and `String toString()`  methods to serialize and deserialize arguments from path.\n\n#### Example\n\n`/article/:[int]id/details?tab\u0026[int]scroll`\n\n* `article` : static segment\n* `id` : required dynamic segment of type `int`\n* `details` : static segment\n* `tab` : optionnal query parameter of type `String`\n* `scroll` : optionnal query parameter of type `int`\n\nThis example will match those URIs :\n\n* `/article/26436/details`\n* `/article/1234/details?tab=second`\n* `/article/98904/details?tab=first\u0026scroll=8`\n\n### Run the generator\n\nTo run the generator, you must use `build_runner` cli:\n\n```sh\nflutter pub pub run build_runner watch\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faloisdeniel%2Froute_pattern_generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faloisdeniel%2Froute_pattern_generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faloisdeniel%2Froute_pattern_generator/lists"}