代码:
1.
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'router_handle.dart';
class MainRouter {
static String root = '/';
static String goodDetail = '/goodsDetail';
static void configureRoutes(Router router){
router.notFoundHandler = new Handler(
handlerFunc: (BuildContext context,Map<String,List<String>> params){
print('Not Found Router');
}
);
router.define(goodDetail, handler: goodsHandle);//商品详情路由
}
}
2.
Handler goodsHandle = Handler(
handlerFunc: (BuildContext context,Map<String,List<String>> params){
String goodsId = params['id'].first;
print('detail->route goodsid : ${goodsId}');
return GoodDetail(goodsId);
}
);
3.
class Application {
static Router router;
}
4.
final router = new Router();
MainRouter.configureRoutes(router);
Application.router = router;
return Container(
child: MaterialApp(
title: '网商项目',
onGenerateRoute: Application.router.generator,
debugShowCheckedModeBanner: false,//去掉debug样式
theme: ThemeData(
primaryColor: Colors.pink//主题样式颜色
),
home: IndexPage(),
),
);
5.
onTap: (){
Application.router.navigateTo(context, '/goodsDetail?id=${val['goodsId']}');
},
总结:
flutter 路由 fluro
下载 fluro: ^1.4.0
单个路由的实例
Handle xxxx = Handle(
handlerFunc:(BuildContext context,Map<String,List<String>> prarams){
print(‘调用XX路由实例’)
return 返回某个页面,也可省略
}
)
Xxx 是实例变量
使用主Route 统一分发
Class YYY{
static String root = ‘/’;
static String xxString = ‘/xxx’ //上面实例相关的实例变量地址
static void yyconfigurationRoutes(Router router){
router.notFoundHandle = new Handle(//未识别到的路由跳转
handleFunc:(BuildContext context,Map<String,List<String>> params){
}
)
router.define(xxString,handle:xxxx)
}
}
yyconfigurationRoutes YYY下的静态实例方法
加载静态管理
class Application {
static Router router;
}
main函数初始化
final yy = New Router();//yy Router变量
YYY.yyconfigurationRoutes(yy);
Application.router = router;
在main函数中的Container使用
onGenerateRoute:Application.router.generator
在某个跳转中使用
onTap: (){
Application.router.navigateTo(context, '/goodsDetail?zzzzz'); goodsDetail就是xxString,zzzz是其他
},