import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import '../../views/home/home_screen.dart'; import '../../views/login/login_screen.dart'; import '../../views/profile/profile_screen.dart'; import '../../views/tenders/tenders_screen.dart'; import '../../views/your_tenders/your_tenders_screen.dart'; import 'app_shell_screen.dart'; part 'app_routes.g.dart'; // Global navigator keys final GlobalKey rootNavigatorKey = GlobalKey(); final GlobalKey homeNavigatorKey = GlobalKey(); final GlobalKey tendersNavigatorKey = GlobalKey(); final GlobalKey profileNavigatorKey = GlobalKey(); // Main app router final GoRouter appRouter = GoRouter( routes: $appRoutes, initialLocation: '/home', navigatorKey: rootNavigatorKey, ); // Login route - outside the shell @TypedGoRoute(path: '/login') class LoginScreenRoute extends GoRouteData with _$LoginScreenRoute { const LoginScreenRoute(); @override Widget build(BuildContext context, GoRouterState state) { return const LoginScreen(); } } // Shell route with bottom navigation using StatefulShellRoute.indexedStack @TypedStatefulShellRoute( branches: >[ TypedStatefulShellBranch( routes: >[ TypedGoRoute(path: '/home'), ], ), TypedStatefulShellBranch( routes: >[ TypedGoRoute(path: '/tenders'), ], ), TypedStatefulShellBranch( routes: >[ TypedGoRoute(path: '/profile'), ], ), ], ) class AppShellRouteData extends StatefulShellRouteData { const AppShellRouteData(); static final GlobalKey $parentNavigatorKey = rootNavigatorKey; @override Widget builder( BuildContext context, GoRouterState state, StatefulNavigationShell navigationShell, ) { return AppShellScreen(navigationShell: navigationShell); } } // Branch data classes class HomeBranch extends StatefulShellBranchData { const HomeBranch(); static final GlobalKey $navigatorKey = homeNavigatorKey; } class TendersBranch extends StatefulShellBranchData { const TendersBranch(); static final GlobalKey $navigatorKey = tendersNavigatorKey; } class ProfileBranch extends StatefulShellBranchData { const ProfileBranch(); static final GlobalKey $navigatorKey = profileNavigatorKey; } // Route data classes class HomeRouteData extends GoRouteData with _$HomeRouteData { const HomeRouteData(); @override Widget build(BuildContext context, GoRouterState state) { return const HomeScreen(); } // @override // Page buildPage(BuildContext context, GoRouterState state) { // return CustomTransitionPage( // key: state.pageKey, // child: const HomeScreen(), // transitionDuration: const Duration(milliseconds: 500), // transitionsBuilder: (context, animation, secondaryAnimation, child) { // const begin = Offset(1.0, 0.0); // From right to left // const end = Offset.zero; // const curve = Curves.linearToEaseOut; // var tween = Tween( // begin: begin, // end: end, // ).chain(CurveTween(curve: curve)); // var offsetAnimation = animation.drive(tween); // return SlideTransition(position: offsetAnimation, child: child); // }, // ); // } } class TendersRouteData extends GoRouteData with _$TendersRouteData { const TendersRouteData(); @override Widget build(BuildContext context, GoRouterState state) { return const TendersScreen(); } } class ProfileRouteData extends GoRouteData with _$ProfileRouteData { const ProfileRouteData(); @override Widget build(BuildContext context, GoRouterState state) { return const ProfileScreen(); } } @TypedGoRoute(path: '/your-tenders') class YourTendersRouteData extends GoRouteData with _$YourTendersRouteData { const YourTendersRouteData(); @override Widget build(BuildContext context, GoRouterState state) { return const YourTendersScreen(); } }