初始化
This commit is contained in:
20
lib/router/modules/common_routes.dart
Normal file
20
lib/router/modules/common_routes.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:app/pages/common/auth/login_page.dart';
|
||||
import 'package:app/pages/common/splash/splash_page.dart';
|
||||
import 'package:app/router/router_config.dart';
|
||||
|
||||
import '../route_paths.dart';
|
||||
|
||||
List<RouterConfig> commonRoutes = [
|
||||
RouterConfig(
|
||||
path: RoutePaths.splash,
|
||||
child: (state) {
|
||||
return SplashPage();
|
||||
},
|
||||
),
|
||||
RouterConfig(
|
||||
path: RoutePaths.login,
|
||||
child: (state) {
|
||||
return LoginPage();
|
||||
},
|
||||
),
|
||||
];
|
||||
20
lib/router/modules/student_routes.dart
Normal file
20
lib/router/modules/student_routes.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:app/pages/student/home/s_home_page.dart';
|
||||
import 'package:app/router/router_config.dart';
|
||||
|
||||
import '../../pages/student/room/s_room_page.dart';
|
||||
import '../route_paths.dart';
|
||||
|
||||
List<RouterConfig> studentRoutes = [
|
||||
RouterConfig(
|
||||
path: RoutePaths.sHome,
|
||||
child: (state) {
|
||||
return SHomePage();
|
||||
},
|
||||
),
|
||||
RouterConfig(
|
||||
path: RoutePaths.sRoom,
|
||||
child: (state) {
|
||||
return SRoomPage();
|
||||
},
|
||||
),
|
||||
];
|
||||
20
lib/router/modules/teacher_routes.dart
Normal file
20
lib/router/modules/teacher_routes.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:app/pages/teacher/home/t_home_page.dart';
|
||||
import 'package:app/pages/teacher/room/t_room_page.dart';
|
||||
import 'package:app/router/router_config.dart';
|
||||
|
||||
import '../route_paths.dart';
|
||||
|
||||
List<RouterConfig> teacherRoutes = [
|
||||
RouterConfig(
|
||||
path: RoutePaths.tHome,
|
||||
child: (state) {
|
||||
return THomePage();
|
||||
},
|
||||
),
|
||||
RouterConfig(
|
||||
path: RoutePaths.tRoom,
|
||||
child: (state) {
|
||||
return TRoomPage();
|
||||
},
|
||||
),
|
||||
];
|
||||
20
lib/router/route_paths.dart
Normal file
20
lib/router/route_paths.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
class RoutePaths {
|
||||
RoutePaths._();
|
||||
|
||||
///闪烁页
|
||||
static const splash = "/";
|
||||
|
||||
///登录
|
||||
static const login = "/login";
|
||||
|
||||
///协议
|
||||
static const agreement = "/agreement";
|
||||
|
||||
///老师端、学生端首页
|
||||
static const tHome = "/t/home";
|
||||
static const sHome = "/s/home";
|
||||
|
||||
///老师端、学生端自习室
|
||||
static const tRoom = "/t/study_room";
|
||||
static const sRoom = "/s/study_room";
|
||||
}
|
||||
16
lib/router/router_config.dart
Normal file
16
lib/router/router_config.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class RouterConfig {
|
||||
String path;
|
||||
FutureOr<String?> Function(BuildContext, GoRouterState)? redirect;
|
||||
Widget Function(GoRouterState) child;
|
||||
|
||||
RouterConfig({
|
||||
required this.path,
|
||||
required this.child,
|
||||
this.redirect,
|
||||
});
|
||||
}
|
||||
28
lib/router/routes.dart
Normal file
28
lib/router/routes.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:app/router/modules/common_routes.dart';
|
||||
import 'package:app/router/modules/student_routes.dart';
|
||||
import 'package:app/router/modules/teacher_routes.dart';
|
||||
import 'package:app/router/route_paths.dart';
|
||||
import 'package:app/router/router_config.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
List<RouterConfig> routeConfigs = [
|
||||
...commonRoutes,
|
||||
...teacherRoutes,
|
||||
...studentRoutes
|
||||
];
|
||||
|
||||
//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.tHome,
|
||||
routes: routes,
|
||||
);
|
||||
Reference in New Issue
Block a user