Giter VIP home page Giter VIP logo

easy_router's Introduction

Language: English | 中文简体

easy_router

License Pub support

A Simple Flutter Page Jump Router

Get started

1. Add dependency

dependencies:
  easy_router: 0.9.4  #latest version

2. How to use

2.1. Add EasyRoutePathAnnotation annotation

//True means that the parameter is required, and the constructor that passes the 
//EasyRouteParam parameter must be added.
@EasyRoutePathAnnotation("pageA", true)
class PageA extends StatelessWidget {
  final EasyRouteParam param;

  PageA(this.param);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Page A"),
      ),
      body: Container(
        alignment: Alignment.center,
        child: Text("param:${param["key"]}"),
      ),
    );
  }
}

//False means no parameters are required, no need to add a constructor that passes the 
//EasyRouteParam parameter
@EasyRoutePathAnnotation("pageB", false)
class PageB extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Page B"),
      ),
      body: Container(
        alignment: Alignment.center,
        child: Text("no param"),
      ),
    );
  }
}

2.2. Add router annotations

Use @EasyRouterAnnotation() to annotate the custom class before you can generate the relevant code with the command, for example

@EasyRouterAnnotation()
class Router {
  
}

2.3. Generate code

cd to your app module and execute the command

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

It is recommended to clean up the previous code before building

flutter packages pub run build_runner clean

2.4. Display page

onPressed: () {
    Navigator.of(context).push(
        MaterialPageRoute(
            builder: (context) {
                return EasyRouter.instance.getWidget("pageA", {"key": "a"});
                //or
                //return EasyRouter.instance.getWidget("pageB");
            },
        ),
    );
}

Recommend wrapping EasyRouter, refer to router.dart in demo

To learn how to generate code using source_gen, check out My Blog

Plugins

Plugins Status
source_gen Pub
build_config Pub
mustache4dart Pub

License

the license is MIT

easy_router's People

Contributors

ikakaxi avatar

Stargazers

 avatar 学习专用 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  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.