fixed TM-171 jira task
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tm_app/views/completion_of_documents/pages/m_completion_of_documents_page.dart';
|
||||
import 'package:tm_app/views/detail/pages/detail_screen.dart';
|
||||
import 'package:tm_app/views/forget_password_create/pages/forgot_password_create_screen.dart';
|
||||
import 'package:tm_app/views/forget_password_otp.dart/pages/forgot_password_otp_screen.dart';
|
||||
import 'package:tm_app/views/forget_password_otp/pages/forgot_password_otp_screen.dart';
|
||||
import 'package:tm_app/views/home/pages/home_screen.dart';
|
||||
import 'package:tm_app/views/liked_tenders/pages/liked_tenders_screen.dart';
|
||||
import 'package:tm_app/views/login/pages/login_screen.dart';
|
||||
@@ -34,6 +36,22 @@ final GoRouter appRouter = GoRouter(
|
||||
routes: $appRoutes,
|
||||
initialLocation: '/splash',
|
||||
navigatorKey: rootNavigatorKey,
|
||||
redirect: (context, state) {
|
||||
final prefs = context.read<SharedPreferences>();
|
||||
final hasToken = prefs.getString('bearer') != null;
|
||||
final path = state.uri.path;
|
||||
final location = state.matchedLocation;
|
||||
final isSplash = path == '/splash' || location == '/splash';
|
||||
final isLogin = path == '/login' || location == '/login';
|
||||
final isForgotFlow =
|
||||
path.startsWith('/forgot-password') ||
|
||||
location.startsWith('/forgot-password');
|
||||
final isPublic = isSplash || isLogin || isForgotFlow;
|
||||
if (!hasToken && !isPublic) {
|
||||
return '/splash';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
// Login route - outside the shell
|
||||
|
||||
Reference in New Issue
Block a user