{"id":32292347,"url":"https://github.com/excitedhaha/router_generator","last_synced_at":"2026-02-23T17:07:56.708Z","repository":{"id":56838355,"uuid":"244294187","full_name":"excitedhaha/router_generator","owner":"excitedhaha","description":"router_generator is a flutter library for router generation.","archived":false,"fork":false,"pushed_at":"2020-03-10T14:58:21.000Z","size":465,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T03:30:48.022Z","etag":null,"topics":["flutter-library"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/excitedhaha.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-02T06:10:50.000Z","updated_at":"2023-02-02T08:15:14.000Z","dependencies_parsed_at":"2022-09-13T04:54:34.709Z","dependency_job_id":null,"html_url":"https://github.com/excitedhaha/router_generator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/excitedhaha/router_generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excitedhaha%2Frouter_generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excitedhaha%2Frouter_generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excitedhaha%2Frouter_generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excitedhaha%2Frouter_generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/excitedhaha","download_url":"https://codeload.github.com/excitedhaha/router_generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/excitedhaha%2Frouter_generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29748882,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T07:44:07.782Z","status":"ssl_error","status_checked_at":"2026-02-23T07:44:07.432Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["flutter-library"],"created_at":"2025-10-23T03:18:39.249Z","updated_at":"2026-02-23T17:07:56.702Z","avatar_url":"https://github.com/excitedhaha.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# router_generator is a flutter library for router generation.\n### [中文文档](https://github.com/excitedhaha/router_generator/blob/master/README_CN.md)\n[![pub package](https://img.shields.io/pub/v/router_generator.svg)](https://pub.dartlang.org/packages/router_generator)\n### install\n```\ndev_dependencies:\n router_generator: ^0.1.2\n build_runner:\n```\n### import\n`import 'package:router_generator/router_generator.dart';`\n### mark page\n```\n@Router('third')\nclass ThirdPage extends StatefulWidget {\n```\nMark the page widget with `Router` annotation，provide the page name as key.\n### mark argumengs\n```\n@inject\nclass ThirdPageState extends State\u003cThirdPage\u003e {\n @RouterParam(required: true)\n Person person;\n @RouterParam(key: 'set_key')\n bool setKey = false;\n @routerParam\n Map\u003cString, int\u003e map;\n```\nAnnotated the state needs dependencies with `inject`.Add arguments in state directly, and annotated them with `RouterParam`。\n`RouterParam `has two args:\n- key: The key of the param, use the field name instead if not provided\n- required：If true, the arguments from route must contains this param\nIf neither params needed，use`routerParam` is recommended.\nFrom the example above，**every types in dart are supported, including custom type**。\n### code generation\nThis library builds on top of source_gen, so you can run the command:`flutter packages pub run build_runner build`, refer to [build_runner](https://pub.dev/packages/build_runner) for more detail.\nGenerated dart files including：\n- A `$root_file.router_table.dart`, has a list of page names and a method for creating widget by page name，root_file is the router table file's prefix.\n- several `$page.inject.dart`，the `page` is your file that contains the marked state， like `foo.dart` to `foo.inject.dart`\n`main.dart` is the default root file of `router_table`file, it can be configured in `build.yaml`:\n```\ntargets:\n  $default:\n    builders:\n      router_generator|router_combining:\n        options:\n          router_table_root_file: \"router.dart\"\n```\n### Use it \n#### GenerateRoute\n```\nMaterialApp(\n  ...\n  onGenerateRoute: (RouteSettings settings) {\n    String pageName = settings.name;\n    var arguments = settings.arguments;\n    if (arguments is Map\u003cString, dynamic\u003e) {\n      deliverParams(pageName, arguments);\n    }\n    return MaterialPageRoute(builder: (_) {\n      return getWidgetByPageName(pageName);\n    });\n  },\n);\n```\nIn the `onGenerateRoute `, call `$root_file.router_table.dart`'s `getWidgetByPageName`，get the page widget，and use `deliverParams() `to deliver params.\nFor the embedding App：\n```\nonGenerateRoute: (RouteSettings settings) {\n    String route = settings.name;\n    Uri uri = Uri.parse(route);\n    var pageName = uri.path.replaceFirst(RegExp('/'), '');\n    lastRouteParams = uri.queryParameters;\n    return PageRouteBuilder(pageBuilder: (BuildContext context,\n        Animation\u003cdouble\u003e animation, Animation\u003cdouble\u003e secondaryAnimation) {\n      return getWidgetByPageName(pageName);\n    });\n  },\n```\nThe params in URI, Map\u003cString, String\u003e is supported, no needs for extra transform.\n#### dependency injection\nIn the state needs dependencies, import the corresponding inject file, and inject before use them：\n```\n@override\nvoid initState() {\n super.initState();\n injectDependencies(this);\n doSometing();\n}\n```\n#### pass argumens\n```\nNavigator.of(context).pushNamed('second',\n arguments: {'name': 'bar', 'count': 666});\n \n```\nYou can create the arguments by hand，but the method in inject file is better\n```\nNavigator.of(context).pushNamed('second',\n arguments: createRouteArgs(name: 'bar', count: 666));\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexcitedhaha%2Frouter_generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexcitedhaha%2Frouter_generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexcitedhaha%2Frouter_generator/lists"}