{"id":32296918,"url":"https://github.com/zhengzaihong/router_lifecycle","last_synced_at":"2026-02-21T16:02:42.991Z","repository":{"id":64497746,"uuid":"575341709","full_name":"zhengzaihong/router_lifecycle","owner":"zhengzaihong","description":"Flutter 页面生命周期的管理，基于Flutter路由2.0跳转工具","archived":false,"fork":false,"pushed_at":"2025-09-04T08:11:30.000Z","size":579,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-04T09:42:00.809Z","etag":null,"topics":["android","flutter","ios","web","windo","windows"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhengzaihong.png","metadata":{"files":{"readme":"README-ZH.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-07T09:46:13.000Z","updated_at":"2025-09-04T08:11:33.000Z","dependencies_parsed_at":"2023-12-23T08:38:27.796Z","dependency_job_id":"c2351c10-6b4b-438c-9ab0-bfc89feba26e","html_url":"https://github.com/zhengzaihong/router_lifecycle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zhengzaihong/router_lifecycle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengzaihong%2Frouter_lifecycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengzaihong%2Frouter_lifecycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengzaihong%2Frouter_lifecycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengzaihong%2Frouter_lifecycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhengzaihong","download_url":"https://codeload.github.com/zhengzaihong/router_lifecycle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhengzaihong%2Frouter_lifecycle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29685044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T15:51:39.154Z","status":"ssl_error","status_checked_at":"2026-02-21T15:49:03.425Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["android","flutter","ios","web","windo","windows"],"created_at":"2025-10-23T04:35:54.657Z","updated_at":"2026-02-21T16:02:42.984Z","avatar_url":"https://github.com/zhengzaihong.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🚀 Router Pro · 路由 \u0026 生命周期感知工具\n\n[![pub package](https://img.shields.io/pub/v/router_pro.svg)](https://pub.dev/packages/router_pro)\n[![GitHub stars](https://img.shields.io/github/stars/zhengzaihong/router_lifecycle.svg?style=social)](https://github.com/zhengzaihong/router_lifecycle)\n[![license](https://img.shields.io/github/license/zhengzaihong/router_lifecycle)](LICENSE)\n\n[English](README.md) | 简体中文\n\n---\n\n## ✨ 为什么选择 Router Pro?\n\n在 Flutter 开发中，页面往往需要像 Android 的 **Activity/Fragment** 一样具备生命周期能力（`onResume`、`onPause`、`onDestroy`），用于懒加载或提升性能体验。  \n但 Flutter 的 **StatelessWidget/StatefulWidget** 并不原生支持这些特性。\n\n**Router Pro 提供了解决方案：**\n\n- 🔗 **路由代理**：更轻松的页面跳转与回退  \n- ⏱ **生命周期感知**：Stateless/StatefulWidget 秒变 Activity/Fragment  \n- 🪶 **解耦设计**：路由与生命周期独立使用  \n- 🌍 **跨平台支持**：App \u0026 Web\n\n---\n\n## 🌟 特点总结\n\n- ✅ Flutter 页面也能享受 **原生生命周期感知**\n- ✅ 提供更优雅的 **路由跳转/关闭 API**\n- ✅ **解耦设计**：路由和生命周期可单独使用\n- ✅ 支持 **跨平台（App \u0026 Web）**\n\n## 📦 安装\n\n在 `pubspec.yaml` 中添加：\n\n```yaml\ndependencies:\n  router_pro: ^0.1.1 //原flutter_router_forzzh：0.0.6（最后版本依赖地址，停止更新）\n```\n\n导入：\n\n```dart\nimport 'package:router_pro/router_lib.dart';\n```\n\n---\n\n## ⚡ 功能一：路由代理（RouterProxy）\n\n### 全局注册\n\n```dart\nRouterProxy router = RouterProxy.getInstance(\n  pageMap: {'/': const Login()},\n  exitWindowStyle: _confirmExit,\n);\n```\n\n```dart\nMaterialApp.router(\n  routerDelegate: router,\n  routeInformationParser: router.defaultParser(),\n);\n```\n\n### 页面跳转\n\n```dart\nrouter.push();  //跳转页面 widget方式\nrouter.pushNamed(); //跳转页面 路由path方式\nrouter.replace(); //替换当前页面\nrouter.popAndPushNamed(); //pop当前页面，然后push一个新页面\nrouter.pushAndRemoveAll();//清空页面栈并push新页面\nrouter.pushNamedAndRemoveAll();// 跳转到指定页面，并清空之前的所有页面\nrouter.pushStackTop();//将页面置于栈顶（如果已存在则先移除）\n\n//举例：\nrouter.push(\n  page:const TaoBaoPageDetail(),\n  onResult: (value){ //可选\n    setState((){\n      title = \"淘宝页面$value\";\n    });\n  });\nrouter.pushNamed(\n  name: '/TaoBaoPageDetail',\n  onResult: (value){ //可选\n    setState((){\n      title = \"淘宝页面$value\";\n    });\n  });\n```\n### 页面关闭 \u0026 回传\n\n```dart\nrouter.pop(); //关闭当前页面\nrouter.popWithResult(); //关闭当前页面,主要用于（dailog,BottomSheet..）\n\n举例：\nrouter.popWithResult(\"返回值：hello\"); //返回值可选\nrouter.pop(\"返回值：hello\"); //返回值可选\n```\n\n### 无需 context 的弹窗\n\n```dart\nrouter.showAppBottomSheet()\nrouter.showAppDialog()\nrouter.showAppSnackBar()\n\n举例：\nrouter.showAppBottomSheet(builder: (context){\n     return  Container(\n       height: 400,\n       width: MediaQuery.of(context).size.width,\n       color: Colors.red,\n       child: GestureDetector(\n         onTap: (){\n           router.popWithResult(\"这是返回结果\");\n         },\n         child: const Text('点击我获取BottomSheet返回值'),\n       ),\n     );\n   }).then((value){\n       debugPrint(\"showAppBottomSheet value:${value}\");\n});\n```\n---\n\n## ⚡ 功能二：生命周期感知\n\n让 **StatelessWidget / StatefulWidget** 具备 `onResume / onPause / onDestroy` 能力：\n\n```dart\nclass Login extends StatelessWidget {\n  const Login({Key? key}) : super(key: key);\n\n  @override\n  Widget build(BuildContext context) {\n    return LifeCycle(\n      onCreate: () =\u003e print(\"Login onCreate\"),\n      onStart: () =\u003e print(\"Login onStart\"),\n      onResume: () =\u003e print(\"Login onResume\"),\n      onPause: () =\u003e print(\"Login onPause\"),\n      onDestroy: () =\u003e print(\"Login onDestroy\"),\n      child: Scaffold(\n        body: Center(\n          child: ElevatedButton(\n            onPressed: () =\u003e router.push(page: NavPage()),\n            child: const Text(\"登录\"),\n          ),\n        ),\n      ),\n    );\n  }\n}\n```\n\n\n\n---\n\n## 🛠 其他说明\n\n- `ExitWindowStyle`：可自定义退出程序提示框\n- Web 端：支持浏览器直达，需要自定义 `RouteParser`\n\n\n\n---\n\n## 🎬 效果演示\n\n![](https://github.com/zhengzaihong/router_lifecycle/blob/master/images/GIF.gif)\n\n\nMIT License © [zhengzaihong](https://github.com/zhengzaihong)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengzaihong%2Frouter_lifecycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhengzaihong%2Frouter_lifecycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhengzaihong%2Frouter_lifecycle/lists"}