The brightest, hippest, coolest router for Flutter.
beta
Flutter channelThere is a pretty sweet example project in the example
folder. Check it out. Otherwise, keep reading to get up and running.
First, you should define a new FluroRouter
object by initializing it as such:
final router = FluroRouter();
It may be convenient for you to store the router globally/statically so that you can access the router in other areas in your application.
After instantiating the router, you will need to define your routes and your route handlers:
var usersHandler = Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
return UsersScreen(params["id"][0]);
});
void defineRoutes(FluroRouter router) {
router.define("/users/:id", handler: usersHandler);
// it is also possible to define the route transition to use
// router.define("users/:id", handler: usersHandler, transitionType: TransitionType.inFromLeft);
}
In the above example, the router will intercept a route such as
/users/1234
and route the application to the UsersScreen
passing
the value 1234
as a parameter to that screen.
You can use FluroRouter
with the MaterialApp.onGenerateRoute
parameter
via FluroRouter.generator
. To do so, pass the function reference to
the onGenerate
parameter like: onGenerateRoute: router.generator
.
You can then use Navigator.push
and the flutter routing mechanism will match the routes
for you.
You can also manually push to a route yourself. To do so:
router.navigateTo(context, "/users/1234", transition: TransitionType.fadeIn);
Don't want to use strings for params? No worries.
After pushing a route with a custom RouteSettings
you can use the BuildContext.settings
extension to extract the settings. Typically this would be done in Handler.handlerFunc
so you can pass RouteSettings.arguments
to your screen widgets.
/// Push a route with custom RouteSettings if you don't want to use path params
FluroRouter.appRouter.navigateTo(
context,
'home',
routeSettings: RouteSettings(
arguments: MyArgumentsDataClass('foo!'),
),
);
/// Extract the arguments using [BuildContext.settings.arguments] or [BuildContext.arguments] for short
var homeHandler = Handler(
handlerFunc: (context, params) {
final args = context.settings.arguments as MyArgumentsDataClass;
return HomeComponent(args);
},
);
about publish https://blog.csdn.net/xiey94/article/details/103474578
1、编写,测试通过;预发布
2、发布前检查
flutter packages pub publish --dry-run 1 一般会有:
author要填写 homepage要填写 .gitignore要填写(一个package不能超过100M,不添加的话可能会超过100M) … 3、环境变量删除
变量名:PUB_HOSTED_URL 变量值:https://pub.flutter-io.cn (注意:这个是临时镜像,学Flitter的都有介绍,不确保一直有效) 变量名:FLUTTER_STORAGE_BASE_URL 变量值:https://storage.flutter-io.cn (注意:这个是临时镜像,学Flitter的都有介绍,不确保一直有效)
4、设置代理
set http_proxy=http://127.0.0.2:1080 set https_proxy=https://127.0.0.2:1080
5、检查过程中会有一次确认是否OK的过程,需要输入(y/n) OK的话直接y
6、会有一次账号验证过程,直接复制那整个链接一直到.email结尾到浏览器进行认证
7.1、发布 -v 能看到整个发布流程
flutter packages pub publish -v 1 7.2、发布
flutter packages pub publish --server=https://pub.dartlang.org 1 因为7.1发布基本上成功率不高,失败率很高,7.2目前试了两次都是一次性OK
8、查找自己的packages,直接搜会搜不到,主要直接查找;或者你的gmail中也会收到邮件里面也会有详细地址
https://pub.dev/packages/#### ####是你的packages name
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。