easy_router 0.9.0 easy_router: ^0.9.0 copied to clipboard
一个简单的路由器框架
easy_router #
A Simple Flutter Page Jump Router
Get started #
1. Add dependency #
dependencies:
easy_router: 0.9.0 #latest version
2. How to use #
2.1. Add EasyRoutePathAnnotation annotation
@EasyRoutePathAnnotation("pageA")
class PageA extends StatelessWidget {
//TODO
}
2.2. easy_router will call the constructor of the page and set the EasyRouteParams parameter, so each page must have a constructor like this
@EasyRoutePathAnnotation("pageA")
class PageA extends StatelessWidget {
final EasyRouteParam param;//here
PageA(this.param);//here
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Page A"),
),
body: Container(
alignment: Alignment.center,
child: Text("param:${param["key"]}"),
),
);
}
}
2.3. 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.4. 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.5. Display page
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return Router.instance.getWidget("pageA", {"key": "a"});
},
),
);
}
Recommend wrapping Router, refer to router.dart
in demo
To learn how to generate code using source_gen, check out My Blog #
Plugins #
Plugins | Status |
---|---|
source_gen | |
build_config | |
mustache4dart |
License #
the license is MIT