a router config mapping solution based on source_gen through annotation
Notice: your page should own a constuctor that can be initialized with unique param, then 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:
flutter packages pub run build_runner build --delete-conflicting-outputs
suggest you running the clean command before build:
clean:
flutter packages pub run build_runner clean
now you can get the instance
example:
@ARouteRoot()
class Router {
ARouterInternal internal = ARouterInternalImpl();
dynamic getPage(MyRouteOption option) {
return internal.findPage(
ARouteOption(option.urlpattern, option.params), option);
}
}
class MyRouteOption {
String urlpattern;
Map<String, dynamic> params;
}
examples placed in 'lib/example/*'
add packages to dev_dependencies in your pubspec.yaml
example:
dev_dependencies:
annotation_route: any
clone the code, then put it into your workspace, announce it in your pubspec.yaml exxample:
dev_dependencies:
annotation_route:
path: annotation_route
一个以注解方式实现的路由映射解决方案,基于 source_gen
注意: 你的页面应该实现指定的构造器,一个接受唯一参数的构造器,然后使用@ARoute 注解你的页面类
例:
@ARoute(url: 'myapp://pagea')
class A {
A(MyRouteOption option): super();
}
使用 @ARouteRoot 注解 你自己的 router 类 例:
@ARouteRoot()
class MyRouter {}
在你的工作目录下运行 build_annotation_route.sh 脚本,或者运行如下命令:
build:
flutter packages pub run build_runner build --delete-conflicting-outputs
建议在执行 build 命令前,先执行如下命令:
clean:
flutter packages pub run build_runner clean
现在你可以使用它来获取类的实例了
例:
@ARouteRoot()
class Router {
ARouterInternal internal = ARouterInternalImpl();
dynamic getPage(MyRouteOption option) {
return internal.findPage(
ARouteOption(option.urlpattern, option.params), option);
}
}
class MyRouteOption {
String urlpattern;
Map<String, dynamic> params;
}
具体代码可以参考 lib/example/*下的文件
在你的 pubspec.yaml 文件下声明
例:
dev_dependencies:
annotation_route: any
拷贝代码至你的工作目录,在你的 pubspec.yaml 文件下声明
例:
dev_dependencies:
annotation_route:
path: annotation_route
Add this to your package's pubspec.yaml file:
dependencies:
annotation_route: ^0.0.2
You can install packages from the command line:
with pub:
$ pub get
Alternatively, your editor might support pub get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:annotation_route/builder.dart';
import 'package:annotation_route/example/page_a.dart';
import 'package:annotation_route/example/page_b.dart';
import 'package:annotation_route/example/page_c.dart';
import 'package:annotation_route/example/page_d.dart';
import 'package:annotation_route/example/router.route.dart';
import 'package:annotation_route/example/router.route.internal.dart';
import 'package:annotation_route/route.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.0.2 | Nov 23, 2018 |
|
|
0.0.1+1 | Nov 19, 2018 |
|
|
0.0.1 | Nov 19, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
68
|
Health:
Code health derived from static analysis.
[more]
|
74
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
40
|
Overall:
Weighted score of the above.
[more]
|
64
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: other
Platform components identified in package:
build
,io
,mirrors
.
Fix lib/example/router.route.dart
. (-25 points)
Analysis of lib/example/router.route.dart
failed with 1 error:
line 6 col 3: The name 'ARouterInternal' is defined in the libraries 'package:annotation_route/example/router.route.internal.dart' and 'package:annotation_route/route.dart'.
Document public APIs. (-1 points)
94 out of 94 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.
Use constrained dependencies. (-20 points)
The pubspec.yaml
contains 5 dependencies without version constraints. Specify version ranges for the following dependencies: analyzer
, build
, build_config
, mustache4dart
, source_gen
.
The package description is too short. (-20 points)
Add more detail to the description
field of pubspec.yaml
. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Maintain an example. (-10 points)
Create a short demo in the example/
directory to show how to use this package.
Common filename patterns include main.dart
, example.dart
, and annotation_route.dart
. Packages with multiple examples should provide example/README.md
.
For more information see the pub package layout conventions.
Package is pre-v0.1 release. (-10 points)
While nothing is inherently wrong with versions of 0.0.*
, it might mean that the author is still experimenting with the general direction of the API.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0 <3.0.0 | ||
analyzer | any | 0.35.1 | |
build | any | 1.1.1 | |
build_config | >=0.3.0 | 0.3.1+4 | |
mustache4dart | any | 3.0.0-dev.0.0 | 3.0.0-dev.1.0 |
source_gen | >=0.8.0 | 0.9.4+1 | |
Transitive dependencies | |||
args | 1.5.1 | ||
async | 2.0.8 | ||
charcode | 1.1.2 | ||
collection | 1.14.11 | ||
convert | 2.1.1 | ||
crypto | 2.0.6 | ||
csslib | 0.14.6 | ||
dart_style | 1.2.3 | ||
front_end | 0.1.11 | ||
glob | 1.1.7 | ||
html | 0.13.3+3 | ||
json_annotation | 2.0.0 | ||
kernel | 0.3.11 | ||
logging | 0.11.3+2 | ||
meta | 1.1.7 | ||
package_config | 1.0.5 | ||
path | 1.6.2 | ||
plugin | 0.2.0+3 | ||
pub_semver | 1.4.2 | ||
pubspec_parse | 0.1.4 | ||
source_span | 1.5.4 | ||
string_scanner | 1.0.4 | ||
term_glyph | 1.1.0 | ||
typed_data | 1.1.6 | ||
utf | 0.9.0+5 | ||
watcher | 0.9.7+10 | ||
yaml | 2.1.15 | ||
Dev dependencies | |||
build_runner | >=0.9.1 | ||
test | any |