annotation_route 0.0.2

annotation_route #

Description #

a router config mapping solution based on source_gen through annotation

Usage #

  1. 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();
    }
    
  2. Annotate your own router class with @ARouteRoot
    example:

    @ARouteRoot()
    class MyRouter {}
    
  3. 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
    
  4. 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;
    }
    
  5. examples placed in 'lib/example/*'

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

简介 #

一个以注解方式实现的路由映射解决方案,基于 source_gen

使用 #

  1. 注意: 你的页面应该实现指定的构造器,一个接受唯一参数的构造器,然后使用@ARoute 注解你的页面类
    例:

    @ARoute(url: 'myapp://pagea')
    class A {
     A(MyRouteOption option): super();
    }
    
  2. 使用 @ARouteRoot 注解 你自己的 router 类 例:

    @ARouteRoot()
    class MyRouter {}
    
  3. 在你的工作目录下运行 build_annotation_route.sh 脚本,或者运行如下命令:
    build:

     flutter packages pub run build_runner build --delete-conflicting-outputs
    

    建议在执行 build 命令前,先执行如下命令:
    clean:

     flutter packages pub run build_runner clean
    
  4. 现在你可以使用它来获取类的实例了
    例:

    @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;
    }
    
  5. 具体代码可以参考 lib/example/*下的文件

安装 #

从 pub 安装 #

在你的 pubspec.yaml 文件下声明
例:

dev_dependencies:
  annotation_route: any

从源码安装 #

拷贝代码至你的工作目录,在你的 pubspec.yaml 文件下声明
例:

dev_dependencies:
  annotation_route:
    path: annotation_route

0.0.1 #

  • Ready for experimentation.

0.0.1+1 #

  • Format code by lint rules.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  annotation_route: ^0.0.2

2. Install it

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.

3. Import it

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
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]
68
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: other

Platform components identified in package: build, io, mirrors.

Health issues and suggestions

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.

Maintenance issues and suggestions

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
analyzer any 0.38.3
build any 1.2.0
build_config >=0.3.0 0.4.1+1
mustache4dart any 3.0.0-dev.0.0 3.0.0-dev.1.0
source_gen >=0.8.0 0.9.4+4
Transitive dependencies
args 1.5.2
async 2.3.0
charcode 1.1.2
checked_yaml 1.0.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.2.10
front_end 0.1.25
glob 1.1.7
html 0.14.0+2
json_annotation 3.0.0
kernel 0.3.25
logging 0.11.3+2
meta 1.1.7
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.5
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
build_runner >=0.9.1
test any