This commit is contained in:
Stephane 2025-07-23 12:06:32 +03:00
parent 14ce881a3c
commit 6b83a1ab5e
4 changed files with 1617 additions and 1604 deletions

View File

@ -0,0 +1,11 @@
import 'package:flutter/material.dart';
class AppColors {
static const primaryBlue =
Color(0xFF04365F); // Replace with your exact logo tone
static const secondaryBlue =
Color(0xFF1976D2); // Replace if your logo has a secondary tone
static const neutralGrey = Color(0xFF8A8A8A);
static const accent =
Color(0xFFF7941D); // Example: if your logo has an orange or accent
}

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,22 @@
// Config/database_config.dart - Version améliorée // Config/database_config.dart
class DatabaseConfig {
// static const String host = '10.0.2.2';
//static const String host = '172.20.10.5';
static const String host = 'localhost';
static const int port = 3306;
static const String username = 'root';
static const String? password = null;
static const String database = 'gico';
import 'dart:io';
import 'dart:async';
class DatabaseConfig {
// Local MySQL settings
static const String localHost = '192.168.88.73';
static const String localUsername = 'guycom';
static const String? localPassword = '3iV59wjRdbuXAPR';
static const String localDatabase = 'guycom';
// Production (public) MySQL settings
static const String prodHost = '185.70.105.157'; static const String prodHost = '185.70.105.157';
static const String prodUsername = 'guycom'; static const String prodUsername = 'guycom';
static const String prodPassword = '3iV59wjRdbuXAPR'; static const String prodPassword = '3iV59wjRdbuXAPR';
static const String prodDatabase = 'guycom'; static const String prodDatabase = 'guycom';
static const int port = 3306;
static const Duration connectionTimeout = Duration(seconds: 30); static const Duration connectionTimeout = Duration(seconds: 30);
static const Duration queryTimeout = Duration(seconds: 15); static const Duration queryTimeout = Duration(seconds: 15);
@ -21,46 +25,72 @@ class DatabaseConfig {
static bool get isDevelopment => false; static bool get isDevelopment => false;
static Map<String, dynamic> getConfig() { /// Build config map for connection
if (isDevelopment) { static Map<String, dynamic> _buildConfig({
return { required String host,
'host': host, required String user,
'port': port, required String? password,
'user': username, required String database,
'password': password, }) {
'database': database, return {
'timeout': connectionTimeout.inSeconds, 'host': host,
}; 'port': port,
} else { 'user': user,
return { 'password': password,
'host': prodHost, 'database': database,
'port': port, 'timeout': connectionTimeout.inSeconds,
'user': prodUsername, };
'password': prodPassword, }
'database': prodDatabase,
'timeout': connectionTimeout.inSeconds, /// TCP check if MySQL server is reachable
}; static Future<bool> isServerReachable(String host, {int port = 3306}) async {
try {
final socket =
await Socket.connect(host, port, timeout: Duration(seconds: 2));
socket.destroy();
return true;
} catch (_) {
return false;
} }
} }
// Validation de la configuration /// Get smart config (local if reachable, otherwise public)
static bool validateConfig() { static Future<Map<String, dynamic>> getSmartConfig() async {
if (await isServerReachable(localHost, port: port)) {
return _buildConfig(
host: localHost,
user: localUsername,
password: localPassword,
database: localDatabase,
);
} else {
return _buildConfig(
host: prodHost,
user: prodUsername,
password: prodPassword,
database: prodDatabase,
);
}
}
/// Validate any config
static bool validateConfig(Map<String, dynamic> config) {
try { try {
final config = getConfig();
return config['host']?.toString().isNotEmpty == true && return config['host']?.toString().isNotEmpty == true &&
config['database']?.toString().isNotEmpty == true && config['database']?.toString().isNotEmpty == true &&
config['user'] != null; config['user'] != null;
} catch (e) { } catch (e) {
print("Erreur de validation de la configuration: $e"); print("Erreur de validation de la configuration: $e");
return false; return false;
} }
} }
// Configuration avec retry automatique /// Add retry config
static Map<String, dynamic> getConfigWithRetry() { static Map<String, dynamic> addRetry(Map<String, dynamic> config) {
final config = getConfig(); return {
config['retryCount'] = 3; ...config,
config['retryDelay'] = 5000; // ms 'retryCount': 3,
return config; 'retryDelay': 5000, // ms
};
} }
} }

View File

@ -44,7 +44,8 @@ class UserController extends GetxController {
final storedRole = prefs.getString('role') ?? ''; final storedRole = prefs.getString('role') ?? '';
final storedUserId = prefs.getInt('user_id') ?? 0; final storedUserId = prefs.getInt('user_id') ?? 0;
final storedPointDeVenteId = prefs.getInt('point_de_vente_id') ?? 0; final storedPointDeVenteId = prefs.getInt('point_de_vente_id') ?? 0;
final storedPointDeVenteDesignation = prefs.getString('point_de_vente_designation') ?? ''; final storedPointDeVenteDesignation =
prefs.getString('point_de_vente_designation') ?? '';
if (storedUsername.isNotEmpty) { if (storedUsername.isNotEmpty) {
try { try {
@ -60,13 +61,13 @@ class UserController extends GetxController {
_pointDeVenteId.value = storedPointDeVenteId; _pointDeVenteId.value = storedPointDeVenteId;
_pointDeVenteDesignation.value = storedPointDeVenteDesignation; _pointDeVenteDesignation.value = storedPointDeVenteDesignation;
if (_pointDeVenteDesignation.value.isEmpty && _pointDeVenteId.value > 0) { if (_pointDeVenteDesignation.value.isEmpty &&
_pointDeVenteId.value > 0) {
await loadPointDeVenteDesignation(); await loadPointDeVenteDesignation();
} }
// Précharger les permissions en arrière-plan (non bloquant) // Précharger les permissions en arrière-plan (non bloquant)
_preloadPermissionsInBackground(); _preloadPermissionsInBackground();
} catch (dbError) { } catch (dbError) {
print("❌ Erreur BDD, utilisation du fallback: $dbError"); print("❌ Erreur BDD, utilisation du fallback: $dbError");
_username.value = storedUsername; _username.value = storedUsername;
@ -105,13 +106,15 @@ class UserController extends GetxController {
if (_pointDeVenteId.value <= 0) return; if (_pointDeVenteId.value <= 0) return;
try { try {
final pointDeVente = await AppDatabase.instance.getPointDeVenteById(_pointDeVenteId.value); final pointDeVente =
await AppDatabase.instance.getPointDeVenteById(_pointDeVenteId.value);
if (pointDeVente != null) { if (pointDeVente != null) {
_pointDeVenteDesignation.value = pointDeVente['nom'] as String; _pointDeVenteDesignation.value = pointDeVente['nom'] as String;
await saveUserData(); await saveUserData();
} }
} catch (e) { } catch (e) {
print('❌ Erreur lors du chargement de la désignation du point de vente: $e'); print(
'❌ Erreur lors du chargement de la désignation du point de vente: $e');
} }
} }
@ -160,7 +163,8 @@ class UserController extends GetxController {
await prefs.setString('lastname', _lastname.value); await prefs.setString('lastname', _lastname.value);
await prefs.setInt('user_id', _userId.value); await prefs.setInt('user_id', _userId.value);
await prefs.setInt('point_de_vente_id', _pointDeVenteId.value); await prefs.setInt('point_de_vente_id', _pointDeVenteId.value);
await prefs.setString('point_de_vente_designation', _pointDeVenteDesignation.value); await prefs.setString(
'point_de_vente_designation', _pointDeVenteDesignation.value);
print("✅ Données sauvegardées avec succès"); print("✅ Données sauvegardées avec succès");
} catch (e) { } catch (e) {
@ -198,7 +202,6 @@ class UserController extends GetxController {
_pointDeVenteDesignation.value = ''; _pointDeVenteDesignation.value = '';
print("✅ Données utilisateur et cache de session vidés"); print("✅ Données utilisateur et cache de session vidés");
} catch (e) { } catch (e) {
print('❌ Erreur lors de l\'effacement: $e'); print('❌ Erreur lors de l\'effacement: $e');
} }
@ -231,12 +234,12 @@ class UserController extends GetxController {
await _cacheService.loadUserPermissions(_username.value); await _cacheService.loadUserPermissions(_username.value);
return _cacheService.hasPermission(_username.value, permission, route); return _cacheService.hasPermission(_username.value, permission, route);
} catch (e) { } catch (e) {
print('❌ Erreur vérification permission: $e'); print('❌ Erreur vérification permission: $e');
// Fallback vers la méthode originale en cas d'erreur // Fallback vers la méthode originale en cas d'erreur
try { try {
return await AppDatabase.instance.hasPermission(_username.value, permission, route); return await AppDatabase.instance
.hasPermission(_username.value, permission, route);
} catch (fallbackError) { } catch (fallbackError) {
print('❌ Erreur fallback permission: $fallbackError'); print('❌ Erreur fallback permission: $fallbackError');
return false; return false;
@ -245,7 +248,8 @@ class UserController extends GetxController {
} }
/// Vérification de permissions multiples /// Vérification de permissions multiples
Future<bool> hasAnyPermission(List<String> permissionNames, String menuRoute) async { Future<bool> hasAnyPermission(
List<String> permissionNames, String menuRoute) async {
for (String permissionName in permissionNames) { for (String permissionName in permissionNames) {
if (await hasPermission(permissionName, menuRoute)) { if (await hasPermission(permissionName, menuRoute)) {
return true; return true;