2 Star 1 Fork 1

kgm / flutter_ref

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README copy.md 4.46 KB
一键复制 编辑 原始数据 按行查看 历史

English | Português



The brightest, hippest, coolest router for Flutter.

Version Build Status

Features

  • Simple route navigation
  • Function handlers (map to a function instead of a route)
  • Wildcard parameter matching
  • Querystring parameter parsing
  • Common transitions built-in
  • Simple custom transition creation
  • Follows beta Flutter channel

Example Project

There is a pretty sweet example project in the example folder. Check it out. Otherwise, keep reading to get up and running.

Getting started

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.

Navigating

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);

Class arguments

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

Dart
1
https://gitee.com/kgm0515/flutter_ref.git
git@gitee.com:kgm0515/flutter_ref.git
kgm0515
flutter_ref
flutter_ref
master

搜索帮助