|
|
@@ -1,14 +1,86 @@
|
|
|
-# router_gen
|
|
|
+# i2School 路由生成工具
|
|
|
|
|
|
-i2 route generate helper
|
|
|
+### 功能介绍
|
|
|
+router_gen 是一个通过注解实现自动化生成路由代码的工具
|
|
|
+功能 **自动参数导入 路径自动生成 路由注册表生成**
|
|
|
|
|
|
-## Getting Started
|
|
|
+### 插件导入
|
|
|
+dependencies添加
|
|
|
+```
|
|
|
+router_gen:
|
|
|
+ git:
|
|
|
+ url: https://git.i2erp.cn/andy.huang/router_gen.git
|
|
|
+```
|
|
|
+dev_dependencies添加
|
|
|
+```
|
|
|
+ build_runner: any
|
|
|
+```
|
|
|
+### 使用方法
|
|
|
+#### 路由表注解
|
|
|
+使用注解@routerTable或@RouterTable()定义路由表类,接着注册RouterTableProvider路由
|
|
|
+```
|
|
|
+import 'package:router_gen/router_gen.dart';
|
|
|
+import 'package:school_parent/router_gen/router_table.route.dart';
|
|
|
+import 'package:school_parent/base_plugin/routes.dart';
|
|
|
|
|
|
-This project is a starting point for a Dart
|
|
|
-[package](https://flutter.dev/developing-packages/),
|
|
|
-a library module containing code that can be shared easily across
|
|
|
-multiple Flutter or Dart projects.
|
|
|
+@routerTable
|
|
|
+abstract class RouterTableProvider extends IRoutesProvider {
|
|
|
+ factory RouterTableProvider() => $RouterTableProvider();
|
|
|
+}
|
|
|
+```
|
|
|
+注意这里import的**router_table.route.dart**是自动生成后的产物,与**RouterTable**在同一个文件夹
|
|
|
+#### 路由类注解
|
|
|
+**@RouterPage(String path)
|
|
|
+@routerParam(@RouterParam())**
|
|
|
|
|
|
-For help getting started with Flutter, view our
|
|
|
-[online documentation](https://flutter.dev/docs), which offers tutorials,
|
|
|
-samples, guidance on mobile development, and a full API reference.
|
|
|
+上个例子 定义类如下
|
|
|
+```
|
|
|
+@RouterPage(path: "example")
|
|
|
+class ExamplePage extends StatefulWidget {
|
|
|
+ @routerParam
|
|
|
+ final String param;
|
|
|
+
|
|
|
+ const ExamplePage({Key key, this.param}) : super(key: key);
|
|
|
+
|
|
|
+ @override
|
|
|
+ _ExamplePageState createState() => _ExamplePageState();
|
|
|
+}
|
|
|
+......
|
|
|
+```
|
|
|
+调用build_runner生成代码
|
|
|
+```
|
|
|
+packages pub run build_runner build
|
|
|
+```
|
|
|
+生成路由表如下
|
|
|
+```
|
|
|
+// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
|
+
|
|
|
+// **************************************************************************
|
|
|
+// RouterTableGenerator
|
|
|
+// **************************************************************************
|
|
|
+
|
|
|
+import 'router_table.dart';
|
|
|
+import 'package:fluro/fluro.dart' as fluro;
|
|
|
+import 'package:school_parent/base_plugin/routes.dart';
|
|
|
+import 'package:school_parent/pages/example_page.dart';
|
|
|
+
|
|
|
+class $RouterTableProvider implements RouterTableProvider {
|
|
|
+ static final example = "/pages/example";
|
|
|
+
|
|
|
+ @override
|
|
|
+ void registerRoutes(fluro.Router router) {
|
|
|
+ router.define(
|
|
|
+ example,
|
|
|
+ handler: fluro.Handler(
|
|
|
+ handlerFunc: (c, p) => ExamplePage(
|
|
|
+ param: IRoutesProvider.getParams<String>(p, "param"),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+```
|
|
|
+##### 参数说明
|
|
|
+- @RouterPage参数说明:当path为"/"开头是以path生成的路由路径,反之生成带文件路径与path拼接的路由路径
|
|
|
+- @RouterParam参数说明:required当前未使用无效果
|