Files
BistroFrontend/lib/router/router_table.dart
李东云 a201fdb91c refactor(router): 改变了路由方式
从路由配置文件改为了路由表
2023-03-29 14:47:31 +08:00

41 lines
971 B
Dart

import 'package:bistro/login.dart';
import 'package:flutter/material.dart';
import '../life.dart';
class RouterTable {
// static String splashPath = 'splash';
static String loginPath = 'login';
static String homePath = '/';
// static String notFoundPath = '404';
static Map<String, WidgetBuilder> routeTables = {
//404页面
// notFoundPath: (context) => NotFound(),
//启动页
// splashPath: (context) => Splash(),
//登录
loginPath: (context) => const Login(),
//首页
homePath: (context) => const Life(),
};
///路由拦截
static Route onGenerateRoute<T extends Object>(RouteSettings settings) {
return MaterialPageRoute<T>(
settings: settings,
builder: (context) {
String name = settings.name!;
// if (routeTables[name] == null) {
// name = notFoundPath;
// }
Widget widget = routeTables[name]!(context);
return widget;
},
);
}
}