2023-02-06 23:45:56 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2023-02-08 23:48:25 +08:00
|
|
|
import 'package:momo/material/detail.dart';
|
2023-02-08 17:20:16 +08:00
|
|
|
import 'package:momo/material/gallery.dart';
|
2023-02-06 23:45:56 +08:00
|
|
|
import 'package:momo/material/home.dart';
|
2023-02-07 17:28:01 +08:00
|
|
|
import 'package:momo/material/login.dart';
|
2023-02-08 17:20:16 +08:00
|
|
|
import 'package:momo/material/profile.dart';
|
2023-02-06 23:45:56 +08:00
|
|
|
|
|
|
|
class MyMaterialRouterConfig {
|
2023-02-07 17:28:01 +08:00
|
|
|
late GoRouter router;
|
|
|
|
|
|
|
|
MyMaterialRouterConfig(String? token) {
|
|
|
|
router = GoRouter(
|
2023-02-09 17:07:14 +08:00
|
|
|
initialLocation: "/",
|
2023-02-07 17:28:01 +08:00
|
|
|
routes: <RouteBase>[
|
2023-02-08 17:20:16 +08:00
|
|
|
ShellRoute(
|
|
|
|
builder: (BuildContext context, GoRouterState state, Widget child) {
|
|
|
|
return HomePage(
|
|
|
|
content: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
routes: [
|
|
|
|
GoRoute(
|
|
|
|
path: "/",
|
|
|
|
pageBuilder: (BuildContext context, GoRouterState state) =>
|
|
|
|
const NoTransitionPage(child: Gallery()),
|
|
|
|
redirect: (BuildContext context, GoRouterState state) {
|
|
|
|
if (token == null || token.isEmpty) {
|
|
|
|
return '/login';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
GoRoute(
|
|
|
|
path: "/profile",
|
|
|
|
pageBuilder: (BuildContext context, GoRouterState state) =>
|
|
|
|
const NoTransitionPage(child: Profile())),
|
|
|
|
GoRoute(
|
|
|
|
path: "/detail",
|
|
|
|
pageBuilder: (BuildContext context, GoRouterState state) =>
|
2023-02-08 23:48:25 +08:00
|
|
|
const NoTransitionPage(child: ImageDetail())),
|
2023-02-08 17:20:16 +08:00
|
|
|
],
|
|
|
|
),
|
2023-02-07 17:28:01 +08:00
|
|
|
GoRoute(
|
2023-02-08 17:20:16 +08:00
|
|
|
path: "/login",
|
2023-02-07 17:28:01 +08:00
|
|
|
builder: (BuildContext context, GoRouterState state) {
|
2023-02-08 17:20:16 +08:00
|
|
|
return const LoginPage();
|
2023-02-07 17:28:01 +08:00
|
|
|
},
|
|
|
|
redirect: (BuildContext context, GoRouterState state) {
|
2023-02-08 17:20:16 +08:00
|
|
|
if (token != null && token.isNotEmpty) {
|
|
|
|
return '/';
|
2023-02-07 17:28:01 +08:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2023-02-06 23:45:56 +08:00
|
|
|
}
|