df
This commit is contained in:
@@ -51,24 +51,36 @@ class AppRouter {
|
|||||||
final isGoingToLogin = state.matchedLocation == '/login';
|
final isGoingToLogin = state.matchedLocation == '/login';
|
||||||
final isGoingToOnboarding = state.matchedLocation == '/onboarding';
|
final isGoingToOnboarding = state.matchedLocation == '/onboarding';
|
||||||
final isGoingToSetPassword = state.matchedLocation == '/set-password';
|
final isGoingToSetPassword = state.matchedLocation == '/set-password';
|
||||||
|
|
||||||
|
// 1. LA PASSATOIA VIP (DEVE ESSERE IN CIMA)
|
||||||
|
// Usiamo state.uri.path perché state.matchedLocation a volte fa i capricci coi deep link iniziali
|
||||||
final isPublicRoute = state.uri.path.startsWith('/upload');
|
final isPublicRoute = state.uri.path.startsWith('/upload');
|
||||||
|
|
||||||
if (isPublicRoute) {
|
if (isPublicRoute) {
|
||||||
return null; // Null significa "Non reindirizzare, lascialo passare"
|
// Ritorna null esplicitamente per dire al router "Rimani qui e non fare altri controlli"
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. CONTROLLO INIZIALE
|
||||||
|
// Se la sessione sta ancora caricando la primissima volta (es. splash screen logico)
|
||||||
if (sessionState.status == SessionStatus.initial) return null;
|
if (sessionState.status == SessionStatus.initial) return null;
|
||||||
|
|
||||||
|
// 3. UTENTE NON LOGGATO (Ma ci arriva solo se non è su /upload)
|
||||||
if (sessionState.status == SessionStatus.unauthenticated) {
|
if (sessionState.status == SessionStatus.unauthenticated) {
|
||||||
|
// Se sta già andando alle uniche altre pagine pubbliche, lascialo andare
|
||||||
if (isGoingToLogin || isGoingToSetPassword) return null;
|
if (isGoingToLogin || isGoingToSetPassword) return null;
|
||||||
|
// Altrimenti bloccalo e mandalo al login
|
||||||
return '/login';
|
return '/login';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. UTENTE LOGGATO MA DEVE COMPLETARE L'ONBOARDING
|
||||||
if (sessionState.status == SessionStatus.onboardingRequired) {
|
if (sessionState.status == SessionStatus.onboardingRequired) {
|
||||||
return isGoingToOnboarding ? null : '/onboarding';
|
return isGoingToOnboarding ? null : '/onboarding';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. UTENTE PERFETTAMENTE LOGGATO E OPERATIVO
|
||||||
if (sessionState.status == SessionStatus.authenticated) {
|
if (sessionState.status == SessionStatus.authenticated) {
|
||||||
|
// Se per sbaglio cerca di tornare al login o all'onboarding, ributtalo in dashboard
|
||||||
if (isGoingToLogin || isGoingToOnboarding) return '/';
|
if (isGoingToLogin || isGoingToOnboarding) return '/';
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import 'package:flux/features/master_data/store/bloc/store_cubit.dart';
|
|||||||
import 'package:flux/features/master_data/store/data/store_repository.dart';
|
import 'package:flux/features/master_data/store/data/store_repository.dart';
|
||||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||||
import 'package:flux/features/settings/settings.dart';
|
import 'package:flux/features/settings/settings.dart';
|
||||||
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@@ -37,7 +38,8 @@ void main() async {
|
|||||||
|
|
||||||
// Inizializza le dipendenze PRIMA di lanciare l'app
|
// Inizializza le dipendenze PRIMA di lanciare l'app
|
||||||
await setupLocator();
|
await setupLocator();
|
||||||
|
// RIMUOVE IL CARATTERE # DAGLI URL WEB!
|
||||||
|
usePathUrlStrategy();
|
||||||
runApp(
|
runApp(
|
||||||
MultiBlocProvider(
|
MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ packages:
|
|||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_web_plugins:
|
flutter_web_plugins:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ dependencies:
|
|||||||
file_picker: ^11.0.2
|
file_picker: ^11.0.2
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
flutter_web_plugins:
|
||||||
|
sdk: flutter
|
||||||
flutter_localizations:
|
flutter_localizations:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_bloc: ^9.1.1
|
flutter_bloc: ^9.1.1
|
||||||
|
|||||||
Reference in New Issue
Block a user