refactoring
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/// Configuration principale de l'application UnionFlow
|
||||
///
|
||||
/// Contient la configuration globale de l'app avec thème, localisation et navigation
|
||||
///
|
||||
/// Thème dynamique (light/dark) via ThemeProvider + localisation + navigation
|
||||
library app;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -11,37 +11,49 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import '../shared/design_system/theme/app_theme_sophisticated.dart';
|
||||
import '../features/authentication/presentation/bloc/auth_bloc.dart';
|
||||
import '../core/l10n/locale_provider.dart';
|
||||
import '../core/theme/theme_provider.dart';
|
||||
import '../core/di/injection.dart';
|
||||
import 'router/app_router.dart';
|
||||
|
||||
/// Application principale avec système d'authentification Keycloak
|
||||
/// Application principale UnionFlow
|
||||
class UnionFlowApp extends StatelessWidget {
|
||||
final LocaleProvider localeProvider;
|
||||
final ThemeProvider themeProvider;
|
||||
|
||||
const UnionFlowApp({super.key, required this.localeProvider});
|
||||
/// Clé globale pour afficher des SnackBars sans BuildContext (ex: session expirée)
|
||||
static final GlobalKey<ScaffoldMessengerState> scaffoldMessengerKey =
|
||||
GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
const UnionFlowApp({
|
||||
super.key,
|
||||
required this.localeProvider,
|
||||
required this.themeProvider,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider.value(value: localeProvider),
|
||||
ChangeNotifierProvider.value(value: themeProvider),
|
||||
BlocProvider(
|
||||
create: (context) => getIt<AuthBloc>()..add(const AuthStatusChecked()),
|
||||
),
|
||||
],
|
||||
child: Consumer<LocaleProvider>(
|
||||
builder: (context, localeProvider, child) {
|
||||
child: Consumer2<LocaleProvider, ThemeProvider>(
|
||||
builder: (context, locale, theme, child) {
|
||||
return MaterialApp(
|
||||
title: 'UnionFlow',
|
||||
debugShowCheckedModeBanner: false,
|
||||
scaffoldMessengerKey: UnionFlowApp.scaffoldMessengerKey,
|
||||
|
||||
// Configuration du thème
|
||||
// Thème dynamique piloté par ThemeProvider
|
||||
theme: AppThemeSophisticated.lightTheme,
|
||||
darkTheme: AppThemeSophisticated.darkTheme,
|
||||
themeMode: ThemeMode.system,
|
||||
themeMode: theme.mode,
|
||||
|
||||
// Configuration de la localisation
|
||||
locale: localeProvider.locale,
|
||||
// Localisation
|
||||
locale: locale.locale,
|
||||
supportedLocales: LocaleProvider.supportedLocales,
|
||||
localizationsDelegates: const [
|
||||
AppLocalizations.delegate,
|
||||
@@ -50,13 +62,11 @@ class UnionFlowApp extends StatelessWidget {
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
|
||||
// Configuration des routes
|
||||
routes: AppRouter.routes,
|
||||
// Routes
|
||||
routes: AppRouter.routes,
|
||||
initialRoute: AppRouter.initialRoute,
|
||||
|
||||
// Page d'accueil par défaut
|
||||
initialRoute: AppRouter.initialRoute,
|
||||
|
||||
// Builder global pour gérer les erreurs
|
||||
// Fix textScaler global
|
||||
builder: (context, child) {
|
||||
return MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
|
||||
@@ -24,21 +24,51 @@ import '../../features/communication/presentation/pages/conversations_page.dart'
|
||||
import '../../features/finance_workflow/presentation/pages/pending_approvals_page.dart';
|
||||
import '../../features/finance_workflow/presentation/pages/budgets_list_page.dart';
|
||||
import '../../core/navigation/main_navigation_layout.dart';
|
||||
import '../../features/onboarding/presentation/pages/onboarding_flow_page.dart';
|
||||
|
||||
/// Configuration des routes de l'application
|
||||
class AppRouter {
|
||||
/// Routes principales de l'application
|
||||
static Map<String, WidgetBuilder> get routes => {
|
||||
'/': (context) => BlocBuilder<AuthBloc, AuthState>(
|
||||
'/': (context) => BlocConsumer<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
// Compte bloqué (SUSPENDU / DESACTIVE) → dialog informatif
|
||||
if (state is AuthAccountNotActive) {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
icon: const Icon(
|
||||
Icons.lock_person_outlined,
|
||||
color: Color(0xFFB71C1C),
|
||||
size: 48,
|
||||
),
|
||||
title: const Text('Accès refusé'),
|
||||
content: Text(state.message),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.of(_).pop(),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is AuthLoading) {
|
||||
return const Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
} else if (state is AuthAuthenticated) {
|
||||
return const MainNavigationLayout();
|
||||
} else if (state is AuthPendingOnboarding) {
|
||||
// OrgAdmin EN_ATTENTE_VALIDATION → workflow d'onboarding
|
||||
return OnboardingFlowPage(
|
||||
onboardingState: state.onboardingState,
|
||||
organisationId: state.organisationId ?? '',
|
||||
souscriptionId: state.souscriptionId,
|
||||
);
|
||||
} else {
|
||||
return const LoginPage();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user