Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>
Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com> Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> modificacion de vistas panel admin, login, animaciones y implementacion de mascota
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:recolecta_app/features/admin/admin_shell.dart';
|
||||
import 'package:recolecta_app/features/auth/login_page.dart';
|
||||
import 'package:recolecta_app/features/splash/splash_screen.dart';
|
||||
import 'package:recolecta_app/features/auth/register_page.dart';
|
||||
import 'package:recolecta_app/features/driver/driver_shell.dart';
|
||||
import 'package:recolecta_app/features/driver/screens/driver_collections_screen.dart';
|
||||
@@ -43,20 +44,21 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
final authState = ref.watch(authControllerProvider);
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/login',
|
||||
initialLocation: '/splash',
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
final isAuthenticated = authState.value?.isAuthenticated ?? false;
|
||||
final role = authState.value?.userRole;
|
||||
|
||||
final isAuthRoute =
|
||||
final isPublicRoute =
|
||||
state.matchedLocation == '/splash' ||
|
||||
state.matchedLocation == '/login' ||
|
||||
state.matchedLocation == '/register';
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return isAuthRoute ? null : '/login';
|
||||
return isPublicRoute ? null : '/login';
|
||||
}
|
||||
|
||||
if (isAuthRoute) {
|
||||
if (isPublicRoute) {
|
||||
switch (role) {
|
||||
case 'admin':
|
||||
return '/admin';
|
||||
@@ -72,6 +74,10 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/splash',
|
||||
builder: (context, state) => const SplashScreen(),
|
||||
),
|
||||
GoRoute(path: '/login', builder: (context, state) => const LoginPage()),
|
||||
GoRoute(
|
||||
path: '/register',
|
||||
|
||||
Reference in New Issue
Block a user