Açıklama Yok

hwh97 d3affe446c fix: 修复part of导入包识别问题 3 yıl önce
lib d3affe446c fix: 修复part of导入包识别问题 3 yıl önce
.gitignore 679df86a23 add: first commit 3 yıl önce
LICENSE 679df86a23 add: first commit 3 yıl önce
README.md 01cf766eb0 update: 更新路由生成工具使用README 3 yıl önce
build.yaml 6997658226 update: 去除全盘扫描导入查询提高生成速度,完善路由参数自动导入判断 3 yıl önce
pubspec.lock a5dc6b1330 add: 完成注解自动化路由生成功能(匹配i2School) 3 yıl önce
pubspec.yaml a5dc6b1330 add: 完成注解自动化路由生成功能(匹配i2School) 3 yıl önce

README.md

i2School 路由生成工具

功能介绍

router_gen 是一个通过注解实现自动化生成路由代码的工具
自动参数导入 路径自动生成 路由注册表生成

插件导入

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';

@routerTable
abstract class RouterTableProvider extends IRoutesProvider {
    factory RouterTableProvider() => $RouterTableProvider();
}

注意这里import的router_table.route.dart是自动生成后的产物,与RouterTable在同一个文件夹

路由类注解

\@RouterPage(String path)
\@routerParam 或者 \@RouterParam()

上个例子 定义类如下

@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生成代码

flutter 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当前未使用无效果