2023-06-21 17:44:28 +08:00
|
|
|
import 'package:flutter/widgets.dart';
|
2023-07-11 23:39:36 +08:00
|
|
|
|
2023-06-21 17:44:28 +08:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-07-11 23:39:36 +08:00
|
|
|
|
2024-04-10 17:15:05 +08:00
|
|
|
import '/router/profile_router.dart';
|
2023-07-17 01:00:16 +08:00
|
|
|
import 'router_key.dart';
|
2023-10-21 21:25:09 +08:00
|
|
|
import 'chat_route.dart';
|
|
|
|
import 'contact_route.dart';
|
|
|
|
import 'more_route.dart';
|
2024-04-09 17:23:28 +08:00
|
|
|
import '/screens/signin_signup/signup_screen.dart';
|
|
|
|
import '/screens/signin_signup/signin_screen.dart';
|
|
|
|
import '/screens/welcome/welcome_screen.dart';
|
|
|
|
import '/screens/home/home_screen.dart';
|
2024-04-10 17:15:05 +08:00
|
|
|
import '/screens/signin_signup/forget_password_screen.dart';
|
2024-04-09 17:23:28 +08:00
|
|
|
import '/notification_api.dart';
|
2023-09-09 16:48:47 +08:00
|
|
|
|
|
|
|
// Used to listen the page transition
|
|
|
|
// https://blog.csdn.net/sinat_17775997/article/details/106570011#:~:text=Flutter%E7%9B%91%E5%90%AC%E8%B7%AF%E7%94%B1%E8%BF%94%E5%9B%9E%20%E6%96%B9%E6%B3%95%E4%B8%80%EF%BC%9A,push%E6%96%B9%E6%B3%95.then%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%8B%E5%8A%BF%E8%BF%94%E5%9B%9E%E2%9C%85%EF%BC%8C%E5%8F%AF%E4%BB%A5%E8%8E%B7%E5%8F%96%E4%BC%A0%E5%9B%9E%E5%8F%82%E6%95%B0%E2%9C%85%E3%80%82%20%E6%96%B9%E6%B3%95%E4%BA%8C%EF%BC%9A%20didPopNext%EF%BC%8C%E6%94%AF%E6%8C%81%E6%89%8B%E5%8A%BF%E8%BF%94%E5%9B%9E%E2%9C%85%EF%BC%8C%E4%BD%86%E5%9B%9E%E4%BC%A0%E5%8F%82%E6%95%B0%E8%8E%B7%E5%8F%96%E4%B8%8D%E5%88%B0%E2%9D%8C%E3%80%82
|
2023-09-10 11:30:20 +08:00
|
|
|
// final RouteObserver<ModalRoute<void>> routeObserver =
|
|
|
|
// RouteObserver<ModalRoute<void>>();
|
2023-06-21 17:44:28 +08:00
|
|
|
|
|
|
|
final GoRouter router = GoRouter(
|
|
|
|
initialLocation: '/welcome',
|
|
|
|
navigatorKey: rootNavigatorKey,
|
|
|
|
debugLogDiagnostics: true,
|
|
|
|
routes: <RouteBase>[
|
|
|
|
GoRoute(
|
|
|
|
path: '/welcome',
|
|
|
|
name: 'Welcome',
|
2024-03-17 01:49:08 +08:00
|
|
|
builder: (BuildContext context, GoRouterState state) {
|
|
|
|
String? isLogout = state.uri.queryParameters['isLogout'];
|
|
|
|
return WelcomeScreen(isLogout: isLogout);
|
2023-07-17 01:00:16 +08:00
|
|
|
},
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/signup',
|
|
|
|
name: 'SignUp',
|
|
|
|
pageBuilder: (context, state) {
|
|
|
|
return CustomTransitionPage(
|
|
|
|
key: state.pageKey,
|
|
|
|
child: const SignupScreen(),
|
|
|
|
transitionDuration: const Duration(milliseconds: 200),
|
|
|
|
reverseTransitionDuration: const Duration(milliseconds: 200),
|
2024-03-17 01:49:08 +08:00
|
|
|
transitionsBuilder: (
|
|
|
|
BuildContext context,
|
|
|
|
Animation<double> animation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
Widget child,
|
|
|
|
) {
|
2023-06-21 17:44:28 +08:00
|
|
|
const begin = Offset(1.0, 0.0);
|
|
|
|
const end = Offset.zero;
|
|
|
|
final tween = Tween(begin: begin, end: end);
|
|
|
|
final offsetAnimation = animation.drive(tween);
|
|
|
|
return SlideTransition(
|
|
|
|
position: offsetAnimation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/signin',
|
|
|
|
name: 'SignIn',
|
|
|
|
pageBuilder: (context, state) {
|
|
|
|
return CustomTransitionPage(
|
|
|
|
key: state.pageKey,
|
|
|
|
child: const SigninScreen(),
|
|
|
|
transitionDuration: const Duration(milliseconds: 200),
|
|
|
|
reverseTransitionDuration: const Duration(milliseconds: 200),
|
|
|
|
transitionsBuilder: (
|
|
|
|
BuildContext context,
|
|
|
|
Animation<double> animation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
Widget child,
|
|
|
|
) {
|
|
|
|
const begin = Offset(1.0, 0.0);
|
|
|
|
const end = Offset.zero;
|
|
|
|
final tween = Tween(begin: begin, end: end);
|
|
|
|
final offsetAnimation = animation.drive(tween);
|
2024-04-10 17:15:05 +08:00
|
|
|
return SlideTransition(
|
|
|
|
position: offsetAnimation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
GoRoute(
|
|
|
|
path: '/forget_password',
|
|
|
|
name: 'ForgetPassword',
|
|
|
|
pageBuilder: (context, state) {
|
|
|
|
return CustomTransitionPage(
|
|
|
|
key: state.pageKey,
|
|
|
|
child: const ForgetPasswordScreen(),
|
|
|
|
transitionDuration: const Duration(milliseconds: 200),
|
|
|
|
reverseTransitionDuration: const Duration(milliseconds: 200),
|
|
|
|
transitionsBuilder: (
|
|
|
|
BuildContext context,
|
|
|
|
Animation<double> animation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
Widget child,
|
|
|
|
) {
|
|
|
|
const begin = Offset(1.0, 0.0);
|
|
|
|
const end = Offset.zero;
|
|
|
|
final tween = Tween(begin: begin, end: end);
|
|
|
|
final offsetAnimation = animation.drive(tween);
|
2023-06-21 17:44:28 +08:00
|
|
|
return SlideTransition(
|
|
|
|
position: offsetAnimation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ShellRoute(
|
|
|
|
navigatorKey: shellNavigatorKey,
|
|
|
|
builder: (BuildContext context, GoRouterState state, Widget child) {
|
|
|
|
int initIndex = 0;
|
|
|
|
if (state.fullPath!.startsWith('/chat')) {
|
|
|
|
initIndex = 0;
|
|
|
|
} else if (state.fullPath!.startsWith('/contact')) {
|
|
|
|
initIndex = 1;
|
|
|
|
} else if (state.fullPath!.startsWith('/more')) {
|
|
|
|
initIndex = 2;
|
|
|
|
}
|
2023-09-09 16:48:47 +08:00
|
|
|
return HomeScreenWithNavBar(
|
2023-09-10 11:30:20 +08:00
|
|
|
notificationAppLaunchDetails:
|
|
|
|
NotificationAPI.notificationAppLaunchDetails,
|
2023-09-09 16:48:47 +08:00
|
|
|
initIndex: initIndex,
|
|
|
|
child: child,
|
|
|
|
);
|
2023-06-21 17:44:28 +08:00
|
|
|
},
|
|
|
|
routes: <RouteBase>[
|
2023-10-21 21:25:09 +08:00
|
|
|
chatRoute,
|
|
|
|
contactRoute,
|
|
|
|
moreRoute,
|
2023-06-21 17:44:28 +08:00
|
|
|
],
|
|
|
|
),
|
2023-10-21 21:25:09 +08:00
|
|
|
myProfileRoute,
|
|
|
|
friendProfileRoute,
|
|
|
|
groupChatProfileRoute,
|
2023-06-21 17:44:28 +08:00
|
|
|
],
|
|
|
|
);
|