基本完成
This commit is contained in:
24
lib/router/config/route_paths.dart
Normal file
24
lib/router/config/route_paths.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
class RoutePaths {
|
||||
RoutePaths._();
|
||||
|
||||
///闪烁页
|
||||
static const splash = "/";
|
||||
|
||||
///协议页
|
||||
static const agreement = "/agreement";
|
||||
|
||||
///登录
|
||||
static const login = "/login";
|
||||
|
||||
///登陆验证码
|
||||
static const loginCode = "/loginCode";
|
||||
|
||||
///首页
|
||||
static const layout = "/layout";
|
||||
|
||||
///预约详情
|
||||
static const detail = "/detail";
|
||||
|
||||
///编辑我的
|
||||
static const myEdit = "/my_edit";
|
||||
}
|
||||
16
lib/router/config/route_type.dart
Normal file
16
lib/router/config/route_type.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class RouteType {
|
||||
String path;
|
||||
FutureOr<String?> Function(BuildContext, GoRouterState)? redirect;
|
||||
Widget Function(GoRouterState) child;
|
||||
|
||||
RouteType({
|
||||
required this.path,
|
||||
required this.child,
|
||||
this.redirect,
|
||||
});
|
||||
}
|
||||
49
lib/router/modules/base.dart
Normal file
49
lib/router/modules/base.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:food_health/layout/layout_page.dart';
|
||||
import 'package:food_health/page/system/login/login_code_page.dart';
|
||||
import 'package:food_health/page/system/splash/splash_page.dart';
|
||||
import 'package:food_health/router/config/route_paths.dart';
|
||||
|
||||
import '../../page/system/agree/agree_page.dart';
|
||||
import '../../page/system/login/login_page.dart';
|
||||
import '../config/route_type.dart';
|
||||
|
||||
List<RouteType> baseRoutes = [
|
||||
RouteType(
|
||||
path: RoutePaths.splash,
|
||||
child: (state) {
|
||||
return SplashPage();
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.agreement,
|
||||
child: (state) {
|
||||
final extra = state.extra as Map<String, String>;
|
||||
return AgreePage(
|
||||
title: extra['title'] ?? "",
|
||||
url: extra['url'] ?? "",
|
||||
);
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.login,
|
||||
child: (state) {
|
||||
return LoginPage();
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.loginCode,
|
||||
child: (state) {
|
||||
final args = state.extra as Map;
|
||||
return LoginCodePage(
|
||||
email: args['email'],
|
||||
password: args['password'],
|
||||
);
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.layout,
|
||||
child: (state) {
|
||||
return LayoutPage();
|
||||
},
|
||||
),
|
||||
];
|
||||
27
lib/router/modules/serve.dart
Normal file
27
lib/router/modules/serve.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:food_health/page/profile/edit/my_edit_page.dart';
|
||||
|
||||
import '../../page/record/detail/record_detail_page.dart';
|
||||
import '../config/route_paths.dart';
|
||||
import '../config/route_type.dart';
|
||||
|
||||
List<RouteType> serverRoutes = [
|
||||
RouteType(
|
||||
path: RoutePaths.myEdit,
|
||||
child: (state) {
|
||||
var extra = state.extra as dynamic;
|
||||
return MyEditPage(
|
||||
userProfile: extra,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
RouteType(
|
||||
path: RoutePaths.detail,
|
||||
child: (state) {
|
||||
var extra = state.extra as dynamic;
|
||||
return RecordDetailPage(
|
||||
detail: extra,
|
||||
);
|
||||
},
|
||||
),
|
||||
];
|
||||
28
lib/router/routes.dart
Normal file
28
lib/router/routes.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'modules/base.dart';
|
||||
import 'config/route_paths.dart';
|
||||
import 'config/route_type.dart';
|
||||
import 'modules/serve.dart';
|
||||
|
||||
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
List<RouteType> routeConfigs = [...baseRoutes, ...serverRoutes];
|
||||
|
||||
//for循环遍历
|
||||
List<RouteBase> routes = routeConfigs.map((item) {
|
||||
return GoRoute(
|
||||
path: item.path,
|
||||
builder: (context, state) {
|
||||
return item.child(state);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
|
||||
//变量命名
|
||||
GoRouter goRouter = GoRouter(
|
||||
initialLocation: RoutePaths.splash,
|
||||
routes: routes,
|
||||
navigatorKey: navigatorKey,
|
||||
);
|
||||
Reference in New Issue
Block a user