import 'package:flutter/widgets.dart'; import 'package:go_router/go_router.dart'; import 'package:together_mobile/screens/contact/friend_group_screen/friend_group_screen.dart'; import 'package:together_mobile/screens/contact_add/contact_add_friend_screen/contact_add_friend_screen.dart'; import 'package:together_mobile/screens/contact_add/search_new_screen.dart'; import 'package:together_mobile/screens/contact/contact_apply_screen/contact_apply_screen.dart'; import 'package:together_mobile/screens/friend_profile/friend_profile_screen.dart'; import 'package:together_mobile/screens/group_chat_profile/group_chat_profile_screen.dart'; import 'package:together_mobile/screens/more/profile_screen/main_profile.dart'; import 'package:together_mobile/screens/more/profile_screen/modify_profile_screens/modify_avatar_screen.dart'; import 'package:together_mobile/screens/more/profile_screen/modify_profile_screens/modify_basic_screen.dart'; import 'package:together_mobile/screens/more/profile_screen/modify_profile_screens/modify_sign_screen.dart'; import 'package:together_mobile/screens/signin_signup/signup_screen.dart'; import 'package:together_mobile/screens/signin_signup/signin_screen.dart'; import 'package:together_mobile/screens/welcome/welcome_screen.dart'; import 'package:together_mobile/screens/home/home_screen.dart'; import 'package:together_mobile/screens/chat/chat_screen.dart'; import 'package:together_mobile/screens/contact/contact_screen.dart'; import 'package:together_mobile/screens/more/more_screen.dart'; import 'package:together_mobile/screens/message/message_screen.dart'; final GlobalKey rootNavigatorKey = GlobalKey(debugLabel: 'root'); final GlobalKey shellNavigatorKey = GlobalKey(debugLabel: 'shell'); final GoRouter router = GoRouter( initialLocation: '/welcome', navigatorKey: rootNavigatorKey, debugLogDiagnostics: true, routes: [ GoRoute( path: '/welcome', name: 'Welcome', builder: (BuildContext context, GoRouterState state) => const WelcomeScreen(), ), 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), transitionsBuilder: (BuildContext context, Animation animation, Animation 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); 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 animation, Animation 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); 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; } return HomeScreenWithNavBar(initIndex: initIndex, child: child); }, routes: [ GoRoute( path: '/chat', name: 'Chat', builder: (context, state) => const ChatScreen(), ), GoRoute( path: '/contact', name: 'Contact', builder: (context, state) => const ContactScreen(), routes: [ GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'add', name: 'AddContact', builder: (context, state) => const SearchNewScreen(), routes: [ GoRoute( path: 'friend', name: 'AddFriend', parentNavigatorKey: rootNavigatorKey, builder: (context, state) => const ContactAddFriendScreen(), ), ], ), GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'apply_list', name: 'ApplyList', builder: (context, state) => const ContactApplyList(), ), GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'friend_group', name: 'FriendGroup', pageBuilder: (context, state) { return CustomTransitionPage( key: state.pageKey, child: const FriendGroupScreen(), transitionDuration: const Duration( milliseconds: 200, ), reverseTransitionDuration: const Duration(milliseconds: 200), transitionsBuilder: ( context, animation, secondaryAnimation, child, ) { 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, ); }, ); }, builder: (context, state) => const FriendGroupScreen(), ), GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'friend_profile', name: 'FriendProfile', builder: (context, state) => const FriendProfileScreen(), ), GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'group_chat_profile', name: 'GroupChatProfile', builder: (context, state) => const GroupChatProfileScreen(), ), ], ), GoRoute( path: '/more', name: 'More', builder: (context, state) => const MoreScreen(), routes: [ GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'profile', name: 'MainProfile', builder: (context, state) => const MainProfile(), routes: [ GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'modify_basic', name: 'ModifyBasic', builder: (context, state) => const ModifyBasicProfile(), ), GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'modify_sign', name: 'ModifySign', builder: (context, state) => const ModifySignScreen(), ), GoRoute( parentNavigatorKey: rootNavigatorKey, path: 'modify_avatar', name: 'ModifyAvatar', builder: (context, state) => const ModifyAvatarScreen(), ), ], ), ], ), ], ), GoRoute( path: '/message', name: 'Message', builder: (context, state) => const MessageScreen(), ), ], );