136 lines
4.0 KiB
Dart
136 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:tm_app/views/detail/detail_screen.dart';
|
|
import '../../views/home/home_screen.dart';
|
|
import '../../views/profile/profile_screen.dart';
|
|
import '../../views/tenders/tenders_screen.dart';
|
|
import 'app_shell_screen.dart';
|
|
|
|
part 'app_routes.g.dart';
|
|
|
|
// Global navigator keys
|
|
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
|
|
final GlobalKey<NavigatorState> homeNavigatorKey = GlobalKey<NavigatorState>();
|
|
final GlobalKey<NavigatorState> tendersNavigatorKey =
|
|
GlobalKey<NavigatorState>();
|
|
final GlobalKey<NavigatorState> profileNavigatorKey =
|
|
GlobalKey<NavigatorState>();
|
|
|
|
// Main app router
|
|
final GoRouter appRouter = GoRouter(
|
|
routes: $appRoutes,
|
|
initialLocation: '/login',
|
|
navigatorKey: rootNavigatorKey,
|
|
);
|
|
|
|
// Login route - outside the shell
|
|
@TypedGoRoute<LoginScreenRoute>(path: '/login')
|
|
class LoginScreenRoute extends GoRouteData with _$LoginScreenRoute {
|
|
const LoginScreenRoute();
|
|
|
|
@override
|
|
Widget build(BuildContext context, GoRouterState state) {
|
|
return const TenderDetailScreen();
|
|
}
|
|
}
|
|
|
|
// Shell route with bottom navigation using StatefulShellRoute.indexedStack
|
|
@TypedStatefulShellRoute<AppShellRouteData>(
|
|
branches: <TypedStatefulShellBranch<StatefulShellBranchData>>[
|
|
TypedStatefulShellBranch<HomeBranch>(
|
|
routes: <TypedRoute<RouteData>>[
|
|
TypedGoRoute<HomeRouteData>(path: '/home'),
|
|
],
|
|
),
|
|
TypedStatefulShellBranch<TendersBranch>(
|
|
routes: <TypedRoute<RouteData>>[
|
|
TypedGoRoute<TendersRouteData>(path: '/tenders'),
|
|
],
|
|
),
|
|
TypedStatefulShellBranch<ProfileBranch>(
|
|
routes: <TypedRoute<RouteData>>[
|
|
TypedGoRoute<ProfileRouteData>(path: '/profile'),
|
|
],
|
|
),
|
|
],
|
|
)
|
|
class AppShellRouteData extends StatefulShellRouteData {
|
|
const AppShellRouteData();
|
|
|
|
static final GlobalKey<NavigatorState> $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<NavigatorState> $navigatorKey = homeNavigatorKey;
|
|
}
|
|
|
|
class TendersBranch extends StatefulShellBranchData {
|
|
const TendersBranch();
|
|
static final GlobalKey<NavigatorState> $navigatorKey = tendersNavigatorKey;
|
|
}
|
|
|
|
class ProfileBranch extends StatefulShellBranchData {
|
|
const ProfileBranch();
|
|
static final GlobalKey<NavigatorState> $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<void> buildPage(BuildContext context, GoRouterState state) {
|
|
// return CustomTransitionPage<void>(
|
|
// 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();
|
|
}
|
|
}
|