Amélioration de la splash_page et du login

This commit is contained in:
d6soft
2025-06-04 16:51:40 +02:00
parent 8c9e9a21c4
commit 41f1db1169
228 changed files with 366459 additions and 6183 deletions

View File

@@ -123,7 +123,7 @@ class AppKeys {
},
1: {
'titre': 'Espèce',
'couleur': 0xFFB87333, // Couleur cuivrée
'couleur': 0xFFDAA520, // Goldenrod
'icon_data': Icons.payments_outlined,
},
2: {

View File

@@ -169,21 +169,13 @@ class UserRepository extends ChangeNotifier {
try {
// Vérifier d'abord si la boîte est ouverte
if (!Hive.isBoxOpen(AppKeys.usersBoxName)) {
try {
Hive.openBox<UserModel>(AppKeys.usersBoxName);
} catch (e) {
debugPrint(
'Erreur lors de l\'ouverture de la boîte utilisateurs: $e');
return null;
}
debugPrint('Boîte users non ouverte, tentative d\'ouverture...');
return null; // Retourner null plutôt que d'essayer d'ouvrir ici
}
// Chercher un utilisateur avec une session active - Il suffit qu'il ait un sessionId
// Chercher un utilisateur avec une session active
final activeUsers = _userBox.values
.where((user) =>
user.sessionId != null && // Vérifier que sessionId n'est pas null
user.sessionId!
.isNotEmpty) // Vérifier que sessionId n'est pas vide
.where((user) => user.sessionId != null && user.sessionId!.isNotEmpty)
.toList();
// S'il y a des utilisateurs actifs, retourner le premier
@@ -267,6 +259,16 @@ class UserRepository extends ChangeNotifier {
}
}
/// Navigation après connexion réussie
void navigateAfterLogin(BuildContext context) {
final user = currentUser;
if (user != null && context.mounted) {
final isAdmin = user.role == 1 || user.role == 2;
context.go(isAdmin ? '/admin' : '/user');
}
}
// Méthode d'inscription (uniquement pour les administrateurs)
Future<bool> register(String email, String password, String name,
String amicaleName, String postalCode, String cityName) async {
@@ -1064,28 +1066,8 @@ class UserRepository extends ChangeNotifier {
}
}
/// Méthode de déconnexion avec affichage d'un overlay de chargement
/// et redirection vers la page de démarrage
/// Cette méthode remplace AuthService.logout
Future<bool> logoutWithUI(BuildContext context) async {
final bool result = await LoadingOverlay.show(
context: context,
spinnerSize: 80.0, // Spinner plus grand
strokeWidth: 6.0, // Trait plus épais
future: logout(),
);
// Si la déconnexion a réussi, rediriger vers la page de démarrage
if (result && context.mounted) {
// Utiliser GoRouter pour naviguer vers la page de démarrage
GoRouter.of(context).go('/');
}
return result;
}
// Logout complet (sans UI)
Future<bool> logout() async {
// Méthode de déconnexion unique avec navigation vers / splash_page
Future<bool> logout(BuildContext context) async {
_isLoading = true;
notifyListeners();
@@ -1097,9 +1079,15 @@ class UserRepository extends ChangeNotifier {
final currentUser = getCurrentUser();
if (currentUser == null) {
debugPrint('Aucun utilisateur connecté, déconnexion terminée');
// Nettoyage en profondeur même si aucun utilisateur n'est connecté
await _deepCleanHiveBoxes();
debugPrint('État isLoggedIn après nettoyage: $isLoggedIn');
// Toujours rediriger avec pushAndRemoveUntil pour forcer la navigation
if (context.mounted) {
debugPrint('Redirection forcée vers / après nettoyage');
context.go('/');
}
return true;
}
@@ -1112,13 +1100,9 @@ class UserRepository extends ChangeNotifier {
await logoutAPI();
} catch (e) {
debugPrint('Erreur lors de la déconnexion API, mais on continue: $e');
// Continuer le processus de déconnexion même si l'API échoue
}
}
// Effacer la session de l'utilisateur
debugPrint('Mise à jour de l\'utilisateur pour effacer la session...');
// Supprimer la session API
setSessionId(null);
@@ -1126,37 +1110,47 @@ class UserRepository extends ChangeNotifier {
_cachedCurrentUser = null;
debugPrint('Cache utilisateur réinitialisé (_cachedCurrentUser = null)');
// MODIFICATION IMPORTANTE: Nettoyage complet de toutes les boîtes Hive
// Nettoyage complet de toutes les boîtes Hive
debugPrint('Nettoyage profond des données Hive après déconnexion...');
await _deepCleanHiveBoxes();
// Vérifier l'état après nettoyage
debugPrint('État isLoggedIn après déconnexion: $isLoggedIn');
debugPrint(
'Valeur de currentUser après déconnexion: ${currentUser != null ? "non null" : "null"}');
// Vérifier si des utilisateurs restent dans la boîte
if (Hive.isBoxOpen(AppKeys.usersBoxName)) {
final remainingUsers = _userBox.values.toList();
debugPrint(
'Nombre d\'utilisateurs restants dans la boîte: ${remainingUsers.length}');
}
// Réinitialiser l'état de HiveResetStateService
hiveResetStateService.reset();
debugPrint('État de HiveResetStateService réinitialisé');
debugPrint('Déconnexion terminée avec succès');
// Forcer la navigation avec pushAndRemoveUntil et attendre
if (context.mounted) {
debugPrint('Navigation forcée vers / après déconnexion');
// Attendre que toutes les opérations asynchrones soient terminées
await Future.delayed(const Duration(milliseconds: 200));
// Navigation forcée qui supprime toute la pile de navigation
context.go('/');
// Alternative si pushAndRemoveUntil ne fonctionne pas
// context.pushReplacementNamed('/');
}
notifyListeners();
return true;
} catch (e) {
debugPrint('Erreur de déconnexion: $e');
// Même en cas d'erreur, essayer de naviguer vers la page d'accueil
if (context.mounted) {
debugPrint('Navigation d\'urgence vers / après erreur');
context.go(
'/',
);
}
return false;
} finally {
_isLoading = false;
notifyListeners();
// Vérification finale
debugPrint('État final isLoggedIn: $isLoggedIn');
}
}

View File

@@ -0,0 +1,13 @@
import 'package:package_info_plus/package_info_plus.dart';
class AppInfoService {
static PackageInfo? _packageInfo;
static Future<void> initialize() async {
_packageInfo = await PackageInfo.fromPlatform();
}
static String get version => _packageInfo?.version ?? '0.0.0';
static String get buildNumber => _packageInfo?.buildNumber ?? '0';
static String get fullVersion => 'v$version+$buildNumber';
}

View File

@@ -1,51 +0,0 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:geosector_app/core/repositories/user_repository.dart';
import 'package:geosector_app/presentation/widgets/loading_overlay.dart';
/// Service qui gère les opérations d'authentification avec affichage d'un overlay de chargement
class AuthService {
final UserRepository _userRepository;
AuthService(this._userRepository);
/// Méthode de connexion avec affichage d'un overlay de chargement
Future<bool> login(BuildContext context, String username, String password,
{required String type}) async {
return await LoadingOverlay.show(
context: context,
spinnerSize: 80.0, // Spinner plus grand
strokeWidth: 6.0, // Trait plus épais
future: _userRepository.login(username, password, type: type),
);
}
/// Méthode de déconnexion avec affichage d'un overlay de chargement
/// et redirection vers la page de démarrage
Future<bool> logout(BuildContext context) async {
final bool result = await LoadingOverlay.show(
context: context,
spinnerSize: 80.0, // Spinner plus grand
strokeWidth: 6.0, // Trait plus épais
future: _userRepository.logout(),
);
// Si la déconnexion a réussi, rediriger vers la page de démarrage
if (result && context.mounted) {
// Utiliser GoRouter pour naviguer vers la page de démarrage
GoRouter.of(context).go('/');
}
return result;
}
/// Vérifie si un utilisateur est connecté
bool isLoggedIn() {
return _userRepository.isLoggedIn;
}
/// Récupère le rôle de l'utilisateur connecté
int getUserRole() {
return _userRepository.getUserRole();
}
}

View File

@@ -7,18 +7,70 @@ class AppTheme {
static const Color accentColor = Color(0xFF00E09D); // Vert
static const Color errorColor = Color(0xFFE41B13); // Rouge
static const Color warningColor = Color(0xFFF7A278); // Orange
static const Color backgroundLightColor =
Color(0xFFF4F5F6); // Gris très clair
static const Color backgroundLightColor = Color(0xFFF4F5F6); // Gris très clair
static const Color backgroundDarkColor = Color(0xFF111827);
static const Color textLightColor = Color(0xFF000000); // Noir
static const Color textDarkColor = Color(0xFFF9FAFB);
// Couleurs de texte supplémentaires
static const Color textSecondaryColor = Color(0xFF7F8C8D);
static const Color textLightSecondaryColor = Color(0xFFBDC3C7);
// Couleurs des boutons
static const Color buttonSuccessColor = Color(0xFF2ECC71);
static const Color buttonDangerColor = Color(0xFFE74C3C);
// Couleurs des charts
static const List<Color> chartColors = [
primaryColor,
accentColor,
errorColor,
warningColor,
secondaryColor,
Color(0xFF9B59B6),
Color(0xFF1ABC9C),
];
// Ombres
static List<BoxShadow> cardShadow = [
BoxShadow(
color: Colors.black.withOpacity(0.05),
spreadRadius: 1,
blurRadius: 10,
offset: const Offset(0, 3),
),
];
static List<BoxShadow> buttonShadow = [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 5,
offset: const Offset(0, 2),
),
];
// Rayons des bordures
static const double borderRadiusSmall = 4.0;
static const double borderRadiusMedium = 8.0;
static const double borderRadiusLarge = 12.0;
static const double borderRadiusXL = 16.0;
static const double borderRadiusRounded = 50.0;
// Espacement
static const double spacingXS = 4.0;
static const double spacingS = 8.0;
static const double spacingM = 16.0;
static const double spacingL = 24.0;
static const double spacingXL = 32.0;
static const double spacingXXL = 48.0;
// Thème clair
static ThemeData get lightTheme {
return ThemeData(
useMaterial3: true,
brightness: Brightness.light,
fontFamily: 'Figtree', // Utilisation directe de la police locale
fontFamily: 'Figtree',
colorScheme: ColorScheme.light(
primary: primaryColor,
secondary: secondaryColor,
@@ -29,24 +81,10 @@ class AppTheme {
onSecondary: Colors.white,
onBackground: textLightColor,
onSurface: textLightColor,
error: errorColor,
),
textTheme: const TextTheme().copyWith(
displayLarge: const TextStyle(fontFamily: 'Figtree'),
displayMedium: const TextStyle(fontFamily: 'Figtree'),
displaySmall: const TextStyle(fontFamily: 'Figtree'),
headlineLarge: const TextStyle(fontFamily: 'Figtree'),
headlineMedium: const TextStyle(fontFamily: 'Figtree'),
headlineSmall: const TextStyle(fontFamily: 'Figtree'),
titleLarge: const TextStyle(fontFamily: 'Figtree'),
titleMedium: const TextStyle(fontFamily: 'Figtree'),
titleSmall: const TextStyle(fontFamily: 'Figtree'),
bodyLarge: const TextStyle(fontFamily: 'Figtree'),
bodyMedium: const TextStyle(fontFamily: 'Figtree'),
bodySmall: const TextStyle(fontFamily: 'Figtree'),
labelLarge: const TextStyle(fontFamily: 'Figtree'),
labelMedium: const TextStyle(fontFamily: 'Figtree'),
labelSmall: const TextStyle(fontFamily: 'Figtree'),
),
scaffoldBackgroundColor: backgroundLightColor,
textTheme: _getTextTheme(textLightColor),
appBarTheme: const AppBarTheme(
backgroundColor: primaryColor,
foregroundColor: Colors.white,
@@ -56,9 +94,10 @@ class AppTheme {
style: ElevatedButton.styleFrom(
backgroundColor: primaryColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: const EdgeInsets.symmetric(horizontal: spacingL, vertical: spacingM),
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
borderRadius: BorderRadius.circular(borderRadiusRounded),
),
textStyle: const TextStyle(
fontFamily: 'Figtree',
@@ -67,35 +106,56 @@ class AppTheme {
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: primaryColor,
side: const BorderSide(color: primaryColor),
padding: const EdgeInsets.symmetric(horizontal: spacingL, vertical: spacingM),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadiusMedium),
),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: primaryColor,
padding: const EdgeInsets.symmetric(horizontal: spacingM, vertical: spacingS),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: backgroundLightColor,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(borderRadiusMedium),
borderSide: BorderSide(
color: textLightColor.withOpacity(0.1),
width: 1,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(borderRadiusMedium),
borderSide: BorderSide(
color: textLightColor.withOpacity(0.1),
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(borderRadiusMedium),
borderSide: const BorderSide(color: primaryColor, width: 2),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
contentPadding: const EdgeInsets.symmetric(horizontal: spacingM, vertical: spacingM),
),
cardTheme: CardTheme(
cardTheme: CardThemeData(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(borderRadiusXL),
),
color: Colors.white,
),
dividerTheme: const DividerThemeData(
color: Color(0xFFECF0F1),
thickness: 1,
space: spacingM,
),
);
}
@@ -105,7 +165,7 @@ class AppTheme {
return ThemeData(
useMaterial3: true,
brightness: Brightness.dark,
fontFamily: 'Figtree', // Utilisation directe de la police locale
fontFamily: 'Figtree',
colorScheme: ColorScheme.dark(
primary: primaryColor,
secondary: secondaryColor,
@@ -116,24 +176,10 @@ class AppTheme {
onSecondary: Colors.white,
onBackground: textDarkColor,
onSurface: textDarkColor,
error: errorColor,
),
textTheme: const TextTheme().copyWith(
displayLarge: const TextStyle(fontFamily: 'Figtree'),
displayMedium: const TextStyle(fontFamily: 'Figtree'),
displaySmall: const TextStyle(fontFamily: 'Figtree'),
headlineLarge: const TextStyle(fontFamily: 'Figtree'),
headlineMedium: const TextStyle(fontFamily: 'Figtree'),
headlineSmall: const TextStyle(fontFamily: 'Figtree'),
titleLarge: const TextStyle(fontFamily: 'Figtree'),
titleMedium: const TextStyle(fontFamily: 'Figtree'),
titleSmall: const TextStyle(fontFamily: 'Figtree'),
bodyLarge: const TextStyle(fontFamily: 'Figtree'),
bodyMedium: const TextStyle(fontFamily: 'Figtree'),
bodySmall: const TextStyle(fontFamily: 'Figtree'),
labelLarge: const TextStyle(fontFamily: 'Figtree'),
labelMedium: const TextStyle(fontFamily: 'Figtree'),
labelSmall: const TextStyle(fontFamily: 'Figtree'),
),
scaffoldBackgroundColor: backgroundDarkColor,
textTheme: _getTextTheme(textDarkColor),
appBarTheme: const AppBarTheme(
backgroundColor: Color(0xFF1F2937),
foregroundColor: Colors.white,
@@ -143,9 +189,10 @@ class AppTheme {
style: ElevatedButton.styleFrom(
backgroundColor: primaryColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
padding: const EdgeInsets.symmetric(horizontal: spacingL, vertical: spacingM),
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
borderRadius: BorderRadius.circular(borderRadiusRounded),
),
textStyle: const TextStyle(
fontFamily: 'Figtree',
@@ -154,37 +201,78 @@ class AppTheme {
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: OutlinedButton.styleFrom(
foregroundColor: primaryColor,
side: const BorderSide(color: primaryColor),
padding: const EdgeInsets.symmetric(horizontal: spacingL, vertical: spacingM),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadiusMedium),
),
),
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: primaryColor,
padding: const EdgeInsets.symmetric(horizontal: spacingM, vertical: spacingS),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: const Color(0xFF374151),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(borderRadiusMedium),
borderSide: BorderSide(
color: textDarkColor.withOpacity(0.1),
width: 1,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(borderRadiusMedium),
borderSide: BorderSide(
color: textDarkColor.withOpacity(0.1),
width: 1,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(borderRadiusMedium),
borderSide: const BorderSide(color: primaryColor, width: 2),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
contentPadding: const EdgeInsets.symmetric(horizontal: spacingM, vertical: spacingM),
),
cardTheme: CardTheme(
cardTheme: CardThemeData(
elevation: 4,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
borderRadius: BorderRadius.circular(borderRadiusXL),
),
color: const Color(0xFF1F2937),
),
dividerTheme: DividerThemeData(
color: textDarkColor.withOpacity(0.1),
thickness: 1,
space: spacingM,
),
);
}
}
// Méthode helper pour générer le TextTheme
static TextTheme _getTextTheme(Color textColor) {
return TextTheme(
displayLarge: TextStyle(fontFamily: 'Figtree', color: textColor),
displayMedium: TextStyle(fontFamily: 'Figtree', color: textColor),
displaySmall: TextStyle(fontFamily: 'Figtree', color: textColor),
headlineLarge: TextStyle(fontFamily: 'Figtree', color: textColor),
headlineMedium: TextStyle(fontFamily: 'Figtree', color: textColor),
headlineSmall: TextStyle(fontFamily: 'Figtree', color: textColor),
titleLarge: TextStyle(fontFamily: 'Figtree', color: textColor),
titleMedium: TextStyle(fontFamily: 'Figtree', color: textColor),
titleSmall: TextStyle(fontFamily: 'Figtree', color: textColor),
bodyLarge: TextStyle(fontFamily: 'Figtree', color: textColor),
bodyMedium: TextStyle(fontFamily: 'Figtree', color: textColor),
bodySmall: TextStyle(fontFamily: 'Figtree', color: textColor.withOpacity(0.7)),
labelLarge: TextStyle(fontFamily: 'Figtree', color: textColor),
labelMedium: TextStyle(fontFamily: 'Figtree', color: textColor.withOpacity(0.7)),
labelSmall: TextStyle(fontFamily: 'Figtree', color: textColor.withOpacity(0.7)),
);
}
}