3import 'package:flutter/material.dart';
4import 'package:go_router/go_router.dart';
5import '../services/auth_service.dart';
6import '../services/check_in_service.dart';
7import '../services/fast_sign_in_service.dart';
8import '../services/service_locator.dart';
9import '../../features/auth/data/datasources/local_datasource/session_local_datasource.dart';
10import '../../features/home/domain/usecases/get_schedule_status_usecase.dart';
11import '../../features/home/domain/entities/res/res_schedule_status_entity.dart';
17 static final AuthGuard
instance = AuthGuard._();
23 FutureOr<String?>
redirect(BuildContext context, GoRouterState state) async {
24 final isAuthenticated = await
_authService.isTokenValid();
25 final isLoginRoute = state.matchedLocation ==
Routes.signInScreen.route;
26 final isSplashRoute = state.matchedLocation ==
Routes.splashScreen.route;
30 if (isSplashRoute || isProcessRoute) {
34 if (isFastSignInActive) {
38 if (!isAuthenticated && !isLoginRoute) {
39 return Routes.signInScreen.route;
42 if (isAuthenticated && isLoginRoute) {
43 if (context.mounted) {
46 final userRole = session?.role;
48 if (userRole != null && userRole !=
"Driver") {
49 return Routes.driverRequestsScreen.route;
54 if (checkIn ==
false) {
55 return Routes.checkInScreen.route;
68 final now = DateTime.now();
69 final dateString =
'${now.day.toString().padLeft(2, '0
')}/${now.month.toString().padLeft(2, '0
')}/${now.year}';
79 (scheduleStatusEntity) {
80 switch (scheduleStatusEntity.status) {
81 case ScheduleStatus.empty:
82 return Routes.startLocationChooserScreen.route;
83 case ScheduleStatus.draft:
84 return Routes.scheduleConfirmationScreen.route;
85 case ScheduleStatus.validated:
86 return Routes.homeScreen.route;
92 return Routes.homeScreen.route;
98 return route ==
Routes.collectionDetailsScreen.route ||
99 route ==
Routes.todayScheduleScreen.route ||
100 route ==
Routes.scheduleConfirmationScreen.route ||
101 route ==
Routes.startLocationChooserScreen.route ||
102 route ==
Routes.weeklyCollectionsScreen.route ||
103 route ==
Routes.endLocationChooserScreen.route ||
104 route ==
Routes.collectionRequestConfirmationScreen.route ||
105 route ==
Routes.collectionRequestInformationScreen.route ||
106 route ==
Routes.collectionRequestSuccessScreen.route ||
107 route ==
Routes.collectionRequestPaymentScreen.route ||
108 route ==
Routes.collectionRequestConfirmationScreen.route;
class AuthGuard extends GoRouteData isProcessPath(String route)
Future< String > _checkScheduleStatusAndRoute(int driverId) async
sealed class AuthenticationState extends Equatable failure
Future< bool > isUserCheckedIn() async
override FutureOr< String?> redirect(BuildContext context, GoRouterState state) async
Future< String > _checkScheduleStatusAndRoute(int driverId) async
static final AuthGuard instance
final FastSignInService _fastSignInService
final AuthService _authService
final SessionLocalDataSource _sessionLocalDataSource