Git Product home page Git Product logo

annotation_route's Introduction

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

annotation_route's People

Contributors

voicewitness avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.