annotation_route 0.0.1+1 annotation_route: ^0.0.1+1 copied to clipboard
auto generate router config
annotation_route #
简介 #
一个以注解方式实现的路由映射解决方案,基于 source_gen
使用 #
- 注意: 你的页面应该实现指定的构造器,构造器接受一个继承于$RouteOption的类,或者直接使用$RouteOption
使用@ARoute 注解你的页面类
例:
@ARoute(url: 'myapp://pagea')
class A {
A(MyRouteOption option): super();
}
- 使用 @ARouteRoot 注解 你自己的 router 类 例:
@ARouteRoot()
class MyRouter {}
- 在你的工作目录下运行 build_annotation_route.sh 脚本,或者运行如下的命令:
flutter packages pub run build_runner build --delete-conflicting-outputs
- 现在你可以使用它来获取类的实例了
例:
class MyRouteOption extends $RouteOption {
}
@ARouteRoot()
class Router {
$RouterInternal internal = \$RouterInternal<MyRouteOption>();
getPage(MyRouteOption option) {
return internal.implFromRouteOption(option);
}
}
安装 #
从 pub 安装 #
在你的 pubspec.yaml 文件下声明
例:
dev_dependencies:
annotation_route: any
从源码安装 #
拷贝代码至你的工作目录,在你的 pubspec.yaml 文件下声明
例:
dev_dependencies:
annotation_route:
path: annotation_route
Description #
a router config mapping solution based on source_gen through annotation
Usage #
- Notice: your page should own a constuctor that can be initialized with a class extend $RouteOption Annotate the page class with @ARoute
example:
@ARoute(url: 'myapp://pagea')
class A {
A(MyRouteOption option): super();
}
- Annotate your own router class with @ARouteRoot
example:
@ARouteRoot()
class MyRouter {}
- run the build_annotation_route.sh in your workspace Or just run the command below in your workspace
build command:
flutter packages pub run build_runner build --delete-conflicting-outputs
- now you can get the instance
example:
class MyRouteOption extends $RouteOption {
}
@ARouteRoot()
class Router {
$RouterInternal internal = \$RouterInternal<MyRouteOption>();
getPage(MyRouteOption option) {
return internal.implFromRouteOption(option);
}
}
Installation #
install from packages #
add packages to dev_dependencies in your pubspec.yaml
example:
dev_dependencies:
annotation_route: any
install from source code #
clone the code, then put it into your workspace, announce it in your pubspec.yaml exxample:
dev_dependencies:
annotation_route:
path: annotation_route