首页 > 其他 > 详细

路由单独模块化

时间:2019-08-23 23:59:10      阅读:415      评论:0      收藏:0      [点我收藏+]


目录
|-pages
|-routes
|—Routes.dart

// routes/Routes.dart
import ‘package:flutter/material.dart‘;

import ‘../pages/Tabs.dart‘;
import ‘../pages/Form.dart‘;
import ‘../pages/Search.dart‘;
import ‘../pages/Product.dart‘;
import ‘../pages/ProductInfo.dart‘;

//配置路由
final routes={
‘/‘:(context)=>Tabs(),
‘/form‘:(context)=>FormPage(),
‘/product‘:(context)=>ProductPage(),
‘/productinfo‘:(context,{arguments})=>ProductInfoPage(arguments:arguments),
‘/search‘:(context,{arguments})=>SearchPage(arguments:arguments),
};

//固定写法
var onGenerateRoute=(RouteSettings settings) {
// 统一处理
final String name = settings.name;
final Function pageContentBuilder = routes[name];
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
builder: (context) =>
pageContentBuilder(context, arguments: settings.arguments));
return route;
}else{
final Route route = MaterialPageRoute(
builder: (context) =>
pageContentBuilder(context));
return route;
}
}
};
————————————————

路由单独模块化

原文:https://www.cnblogs.com/ly570/p/11402903.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!