Flutter中fluro使用

0.引入

fluro: "^1.4.0"

1.定义路由final

router = FluroRouter();

放到全局变量中去

class Application{
  static FluroRouter router;
}

在程序最开始的main()入口程序的build中声明注册

final router = FluroRouter();
Routes.configureRoutes(router);
Application.router = router;

然后,在对应的MaterialApp中添加一段代码

onGenerateRoute: Application.router.generator,

其中的Routes.configureRoutes(router);见第三步定义的。

2.定义一个路由规则

Handler commandHandler = Handler(
    handlerFunc: (BuildContext context, Map<String, dynamic> params){
      String id = params['id'][0];
      print('index>details goodsID is ${id}');
      return MyApp(id);

    }
);

3.自定义路由配置

class Routes{
  static String root='/test/';
  static String commandPage = 'command'; //路由路径
  static void configureRoutes(FluroRouter router){
    router.notFoundHandler= new Handler(
      handlerFunc: (BuildContext context,Map<String,List<String>> params){
        print('ERROR====>ROUTE WAS NOT FONUND!!!');
      }
    );

    //每一个路由规则都需要在这里进行新的定义
    router.define(root + commandPage, commandHandler);
  }

4.使用

在需要使用路由的地方,比如说跳转

Application.router.navigateTo(context,"/command?id=234}");

其中id是在路由规则commandHandler中声明的参数key;/command是在Routes中声明的路由路径。

“打完收工!”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值