Files
2025-11-17 16:02:04 +00:00

1479 lines
46 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
/// Page Paramètres Système - UnionFlow Mobile
///
/// Page complète de gestion des paramètres système avec configuration globale,
/// maintenance, monitoring, sécurité et administration avancée.
class SystemSettingsPage extends StatefulWidget {
const SystemSettingsPage({super.key});
@override
State<SystemSettingsPage> createState() => _SystemSettingsPageState();
}
class _SystemSettingsPageState extends State<SystemSettingsPage>
with TickerProviderStateMixin {
late TabController _tabController;
// États des paramètres système
bool _maintenanceMode = false;
bool _debugMode = false;
bool _analyticsEnabled = true;
bool _crashReportingEnabled = true;
bool _autoBackupEnabled = true;
bool _sslEnforced = true;
bool _apiLoggingEnabled = false;
bool _performanceMonitoring = true;
String _selectedLogLevel = 'INFO';
String _selectedBackupFrequency = 'Quotidien';
String _selectedCacheStrategy = 'Intelligent';
final List<String> _logLevels = ['DEBUG', 'INFO', 'WARN', 'ERROR'];
final List<String> _backupFrequencies = ['Temps réel', 'Horaire', 'Quotidien', 'Hebdomadaire'];
final List<String> _cacheStrategies = ['Agressif', 'Intelligent', 'Conservateur', 'Désactivé'];
@override
void initState() {
super.initState();
_tabController = TabController(length: 5, vsync: this);
_loadSystemSettings();
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF8F9FA),
body: Column(
children: [
// Header harmonisé
_buildHeader(),
// Onglets
_buildTabBar(),
// Contenu des onglets
Expanded(
child: TabBarView(
controller: _tabController,
children: [
_buildGeneralTab(),
_buildSecurityTab(),
_buildPerformanceTab(),
_buildMaintenanceTab(),
_buildMonitoringTab(),
],
),
),
],
),
);
}
/// Header harmonisé avec indicateurs système
Widget _buildHeader() {
return Container(
margin: const EdgeInsets.all(SpacingTokens.lg),
padding: const EdgeInsets.all(SpacingTokens.xxl),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: ColorTokens.primaryGradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(SpacingTokens.xl),
boxShadow: [
BoxShadow(
color: ColorTokens.primary.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Column(
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(
Icons.settings,
color: Colors.white,
size: 24,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Paramètres Système',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Configuration globale et administration',
style: TextStyle(
fontSize: 14,
color: Colors.white.withOpacity(0.8),
),
),
],
),
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(8),
),
child: IconButton(
onPressed: () => _showSystemStatus(),
icon: const Icon(
Icons.monitor_heart,
color: Colors.white,
),
tooltip: 'État du système',
),
),
const SizedBox(width: 8),
Container(
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(8),
),
child: IconButton(
onPressed: () => _exportSystemConfig(),
icon: const Icon(
Icons.download,
color: Colors.white,
),
tooltip: 'Exporter la configuration',
),
),
],
),
],
),
const SizedBox(height: 16),
// Indicateurs système
Row(
children: [
Expanded(
child: _buildSystemIndicator(
'Statut',
_maintenanceMode ? 'Maintenance' : 'Opérationnel',
_maintenanceMode ? Icons.build : Icons.check_circle,
_maintenanceMode ? Colors.orange : Colors.green,
),
),
const SizedBox(width: 12),
Expanded(
child: _buildSystemIndicator(
'Charge CPU',
'23%',
Icons.memory,
Colors.blue,
),
),
const SizedBox(width: 12),
Expanded(
child: _buildSystemIndicator(
'Utilisateurs',
'1,247',
Icons.people,
Colors.purple,
),
),
],
),
],
),
);
}
/// Indicateur système
Widget _buildSystemIndicator(String label, String value, IconData icon, Color color) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: Column(
children: [
Icon(
icon,
color: Colors.white,
size: 20,
),
const SizedBox(height: 4),
Text(
value,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
label,
style: TextStyle(
fontSize: 10,
color: Colors.white.withOpacity(0.8),
),
),
],
),
);
}
/// Barre d'onglets
Widget _buildTabBar() {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: TabBar(
controller: _tabController,
labelColor: ColorTokens.primary,
unselectedLabelColor: ColorTokens.onSurfaceVariant,
indicatorColor: ColorTokens.primary,
indicatorWeight: 3,
indicatorSize: TabBarIndicatorSize.tab,
labelStyle: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 10,
),
unselectedLabelStyle: const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 10,
),
tabs: const [
Tab(
icon: Icon(Icons.tune, size: 16),
text: 'Général',
),
Tab(
icon: Icon(Icons.security, size: 16),
text: 'Sécurité',
),
Tab(
icon: Icon(Icons.speed, size: 16),
text: 'Performance',
),
Tab(
icon: Icon(Icons.build, size: 16),
text: 'Maintenance',
),
Tab(
icon: Icon(Icons.analytics, size: 16),
text: 'Monitoring',
),
],
),
);
}
/// Onglet général
Widget _buildGeneralTab() {
return SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
// Configuration de base
_buildSettingsSection(
'Configuration de base',
'Paramètres fondamentaux du système',
Icons.settings,
[
_buildSwitchSetting(
'Mode maintenance',
'Désactiver l\'accès utilisateur pour maintenance',
_maintenanceMode,
(value) {
setState(() => _maintenanceMode = value);
_showMaintenanceModeDialog(value);
},
isWarning: true,
),
_buildSwitchSetting(
'Mode debug',
'Activer les logs détaillés et outils de débogage',
_debugMode,
(value) {
setState(() => _debugMode = value);
_showSuccessSnackBar('Mode debug ${value ? 'activé' : 'désactivé'}');
},
),
_buildDropdownSetting(
'Niveau de logs',
'Détail des informations enregistrées',
_selectedLogLevel,
_logLevels,
(value) => setState(() => _selectedLogLevel = value!),
),
],
),
const SizedBox(height: 16),
// Gestion des données
_buildSettingsSection(
'Gestion des données',
'Configuration du stockage et cache',
Icons.storage,
[
_buildDropdownSetting(
'Stratégie de cache',
'Politique de mise en cache des données',
_selectedCacheStrategy,
_cacheStrategies,
(value) => setState(() => _selectedCacheStrategy = value!),
),
_buildActionSetting(
'Vider le cache système',
'Supprimer tous les fichiers temporaires (2.3 GB)',
Icons.delete_sweep,
const Color(0xFFE17055),
() => _clearSystemCache(),
),
_buildActionSetting(
'Optimiser la base de données',
'Réorganiser et compacter la base de données',
Icons.tune,
const Color(0xFF0984E3),
() => _optimizeDatabase(),
),
],
),
const SizedBox(height: 16),
// Configuration réseau
_buildSettingsSection(
'Configuration réseau',
'Paramètres de connectivité',
Icons.network_check,
[
_buildInfoSetting('Serveur API', 'https://api.unionflow.com'),
_buildInfoSetting('Serveur d\'authentification', 'https://auth.unionflow.com'),
_buildInfoSetting('CDN Assets', 'https://cdn.unionflow.com'),
_buildActionSetting(
'Tester la connectivité',
'Vérifier la connexion aux services',
Icons.network_ping,
const Color(0xFF00B894),
() => _testConnectivity(),
),
],
),
const SizedBox(height: 80),
],
),
);
}
/// Onglet sécurité
Widget _buildSecurityTab() {
return SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
// Sécurité réseau
_buildSettingsSection(
'Sécurité réseau',
'Protection des communications',
Icons.security,
[
_buildSwitchSetting(
'Forcer HTTPS/SSL',
'Obliger les connexions sécurisées',
_sslEnforced,
(value) {
setState(() => _sslEnforced = value);
_showSuccessSnackBar('SSL ${value ? 'obligatoire' : 'optionnel'}');
},
),
_buildSwitchSetting(
'Logs des API',
'Enregistrer toutes les requêtes API',
_apiLoggingEnabled,
(value) {
setState(() => _apiLoggingEnabled = value);
_showSuccessSnackBar('Logs API ${value ? 'activés' : 'désactivés'}');
},
),
_buildActionSetting(
'Régénérer les clés API',
'Créer de nouvelles clés d\'authentification',
Icons.vpn_key,
const Color(0xFFE17055),
() => _regenerateApiKeys(),
),
],
),
const SizedBox(height: 16),
// Authentification
_buildSettingsSection(
'Authentification',
'Gestion des accès utilisateurs',
Icons.login,
[
_buildInfoSetting('Sessions actives', '1,247 utilisateurs connectés'),
_buildInfoSetting('Tentatives échouées', '23 dans les dernières 24h'),
_buildActionSetting(
'Forcer la déconnexion globale',
'Déconnecter tous les utilisateurs',
Icons.logout,
Colors.red,
() => _forceGlobalLogout(),
),
_buildActionSetting(
'Réinitialiser les sessions',
'Nettoyer les sessions expirées',
Icons.refresh,
const Color(0xFF0984E3),
() => _resetSessions(),
),
],
),
const SizedBox(height: 16),
// Audit et conformité
_buildSettingsSection(
'Audit et conformité',
'Traçabilité et réglementation',
Icons.fact_check,
[
_buildActionSetting(
'Générer rapport d\'audit',
'Créer un rapport complet des activités',
Icons.assessment,
ColorTokens.primary,
() => _generateAuditReport(),
),
_buildActionSetting(
'Export RGPD',
'Exporter toutes les données utilisateurs',
Icons.download,
const Color(0xFF00B894),
() => _exportGDPRData(),
),
_buildActionSetting(
'Purge des données',
'Supprimer les données expirées (RGPD)',
Icons.auto_delete,
const Color(0xFFE17055),
() => _purgeExpiredData(),
),
],
),
const SizedBox(height: 80),
],
),
);
}
/// Onglet performance
Widget _buildPerformanceTab() {
return SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
// Monitoring système
_buildSettingsSection(
'Monitoring système',
'Surveillance des performances',
Icons.monitor,
[
_buildSwitchSetting(
'Monitoring des performances',
'Surveiller CPU, mémoire et réseau',
_performanceMonitoring,
(value) {
setState(() => _performanceMonitoring = value);
_showSuccessSnackBar('Monitoring ${value ? 'activé' : 'désactivé'}');
},
),
_buildSwitchSetting(
'Rapports de crash',
'Envoyer automatiquement les rapports d\'erreur',
_crashReportingEnabled,
(value) {
setState(() => _crashReportingEnabled = value);
_showSuccessSnackBar('Rapports de crash ${value ? 'activés' : 'désactivés'}');
},
),
_buildSwitchSetting(
'Analytics système',
'Collecter des données d\'utilisation anonymes',
_analyticsEnabled,
(value) {
setState(() => _analyticsEnabled = value);
_showSuccessSnackBar('Analytics ${value ? 'activées' : 'désactivées'}');
},
),
],
),
const SizedBox(height: 16),
// Métriques en temps réel
_buildSettingsSection(
'Métriques en temps réel',
'État actuel du système',
Icons.speed,
[
_buildMetricItem('CPU', '23%', Icons.memory, Colors.blue),
_buildMetricItem('RAM', '67%', Icons.storage, Colors.green),
_buildMetricItem('Disque', '45%', Icons.storage, Colors.orange),
_buildMetricItem('Réseau', '12 MB/s', Icons.network_check, Colors.purple),
],
),
const SizedBox(height: 16),
// Optimisation
_buildSettingsSection(
'Optimisation',
'Améliorer les performances',
Icons.tune,
[
_buildActionSetting(
'Analyser les performances',
'Scanner les goulots d\'étranglement',
Icons.analytics,
const Color(0xFF0984E3),
() => _analyzePerformance(),
),
_buildActionSetting(
'Nettoyer les logs anciens',
'Supprimer les logs de plus de 30 jours',
Icons.cleaning_services,
const Color(0xFFE17055),
() => _cleanOldLogs(),
),
_buildActionSetting(
'Redémarrer les services',
'Relancer tous les services système',
Icons.restart_alt,
Colors.red,
() => _restartServices(),
),
],
),
const SizedBox(height: 80),
],
),
);
}
/// Onglet maintenance
Widget _buildMaintenanceTab() {
return SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
// Sauvegarde et restauration
_buildSettingsSection(
'Sauvegarde et restauration',
'Gestion des données critiques',
Icons.backup,
[
_buildSwitchSetting(
'Sauvegarde automatique',
'Sauvegarder automatiquement les données',
_autoBackupEnabled,
(value) {
setState(() => _autoBackupEnabled = value);
_showSuccessSnackBar('Sauvegarde auto ${value ? 'activée' : 'désactivée'}');
},
),
_buildDropdownSetting(
'Fréquence de sauvegarde',
'Intervalle entre les sauvegardes',
_selectedBackupFrequency,
_backupFrequencies,
(value) => setState(() => _selectedBackupFrequency = value!),
),
_buildActionSetting(
'Créer une sauvegarde maintenant',
'Sauvegarder immédiatement toutes les données',
Icons.save,
const Color(0xFF00B894),
() => _createBackup(),
),
_buildActionSetting(
'Restaurer depuis une sauvegarde',
'Récupérer des données depuis un fichier',
Icons.restore,
const Color(0xFF0984E3),
() => _restoreFromBackup(),
),
],
),
const SizedBox(height: 16),
// Maintenance système
_buildSettingsSection(
'Maintenance système',
'Opérations de maintenance',
Icons.build,
[
_buildInfoSetting('Dernière maintenance', '15/12/2024 à 02:30'),
_buildInfoSetting('Prochaine maintenance', '22/12/2024 à 02:00'),
_buildActionSetting(
'Planifier une maintenance',
'Programmer une fenêtre de maintenance',
Icons.schedule,
ColorTokens.primary,
() => _scheduleMaintenance(),
),
_buildActionSetting(
'Maintenance d\'urgence',
'Lancer immédiatement une maintenance',
Icons.warning,
Colors.red,
() => _emergencyMaintenance(),
),
],
),
const SizedBox(height: 16),
// Mise à jour système
_buildSettingsSection(
'Mise à jour système',
'Gestion des versions',
Icons.system_update,
[
_buildInfoSetting('Version actuelle', 'UnionFlow Server 2.1.0'),
_buildInfoSetting('Dernière vérification', 'Il y a 2 heures'),
_buildActionSetting(
'Vérifier les mises à jour',
'Rechercher les nouvelles versions',
Icons.refresh,
const Color(0xFF0984E3),
() => _checkUpdates(),
),
_buildActionSetting(
'Historique des mises à jour',
'Voir les versions précédentes',
Icons.history,
ColorTokens.primary,
() => _showUpdateHistory(),
),
],
),
const SizedBox(height: 80),
],
),
);
}
/// Onglet monitoring
Widget _buildMonitoringTab() {
return SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
// Alertes système
_buildSettingsSection(
'Alertes système',
'Notifications d\'état critique',
Icons.notifications_active,
[
_buildAlertItem(
'CPU élevé',
'Alerte si CPU > 80% pendant 5 min',
true,
const Color(0xFFE17055),
),
_buildAlertItem(
'Mémoire faible',
'Alerte si RAM < 20% disponible',
true,
const Color(0xFFE17055),
),
_buildAlertItem(
'Disque plein',
'Alerte si stockage > 90%',
true,
Colors.red,
),
_buildAlertItem(
'Connexions échouées',
'Alerte si > 100 échecs/min',
false,
const Color(0xFF0984E3),
),
],
),
const SizedBox(height: 16),
// Logs système
_buildSettingsSection(
'Logs système',
'Journaux d\'activité',
Icons.article,
[
_buildLogItem('Erreurs critiques', '3', Colors.red),
_buildLogItem('Avertissements', '27', Colors.orange),
_buildLogItem('Informations', '1,247', Colors.blue),
_buildLogItem('Debug', '5,892', Colors.grey),
_buildActionSetting(
'Voir tous les logs',
'Ouvrir la console de logs complète',
Icons.terminal,
ColorTokens.primary,
() => _viewAllLogs(),
),
_buildActionSetting(
'Exporter les logs',
'Télécharger les logs pour analyse',
Icons.download,
const Color(0xFF00B894),
() => _exportLogs(),
),
],
),
const SizedBox(height: 16),
// Statistiques d'utilisation
_buildSettingsSection(
'Statistiques d\'utilisation',
'Métriques d\'activité',
Icons.bar_chart,
[
_buildStatItem('Utilisateurs actifs (24h)', '1,247'),
_buildStatItem('Requêtes API (1h)', '45,892'),
_buildStatItem('Données transférées', '2.3 GB'),
_buildStatItem('Temps de réponse moyen', '127ms'),
_buildActionSetting(
'Rapport détaillé',
'Générer un rapport complet d\'utilisation',
Icons.assessment,
ColorTokens.primary,
() => _generateUsageReport(),
),
],
),
const SizedBox(height: 80),
],
),
);
}
// ==================== MÉTHODES DE CONSTRUCTION DES COMPOSANTS ====================
/// Section de paramètres
Widget _buildSettingsSection(
String title,
String subtitle,
IconData icon,
List<Widget> children,
) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, color: Colors.grey[600], size: 20),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[800],
),
),
Text(
subtitle,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
),
],
),
),
],
),
const SizedBox(height: 16),
...children.map((child) => Padding(
padding: const EdgeInsets.only(bottom: 12),
child: child,
)),
],
),
);
}
/// Paramètre avec switch
Widget _buildSwitchSetting(
String title,
String subtitle,
bool value,
Function(bool) onChanged, {
bool isWarning = false,
}) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: isWarning ? Colors.orange.withOpacity(0.05) : Colors.grey[50],
borderRadius: BorderRadius.circular(12),
border: isWarning ? Border.all(color: Colors.orange.withOpacity(0.3)) : null,
),
child: Row(
children: [
if (isWarning)
const Icon(Icons.warning, color: ColorTokens.warning, size: 20)
else
const Icon(Icons.toggle_on, color: ColorTokens.primary, size: 20),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: isWarning ? Colors.orange[800] : const Color(0xFF1F2937),
),
),
Text(
subtitle,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
),
],
),
),
Switch(
value: value,
onChanged: onChanged,
activeColor: isWarning ? ColorTokens.warning : ColorTokens.primary,
),
],
),
);
}
/// Paramètre avec dropdown
Widget _buildDropdownSetting(
String title,
String subtitle,
String value,
List<String> options,
Function(String?) onChanged,
) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.arrow_drop_down, color: ColorTokens.primary, size: 20),
const SizedBox(width: SpacingTokens.lg),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1F2937),
),
),
Text(
subtitle,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
),
],
),
),
],
),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.grey[300]!),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
value: value,
isExpanded: true,
onChanged: onChanged,
items: options.map((option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
),
],
),
);
}
/// Paramètre d'action
Widget _buildActionSetting(
String title,
String subtitle,
IconData icon,
Color color,
VoidCallback onTap,
) {
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: color.withOpacity(0.1)),
),
child: Row(
children: [
Icon(icon, color: color, size: 20),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: color,
),
),
Text(
subtitle,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
),
],
),
),
Icon(Icons.arrow_forward_ios, color: Colors.grey[400], size: 16),
],
),
),
);
}
/// Paramètre d'information
Widget _buildInfoSetting(String title, String value) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(Icons.info_outline, color: Colors.grey[600], size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(
title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1F2937),
),
),
),
Text(
value,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
fontWeight: FontWeight.w600,
),
),
],
),
);
}
/// Élément de métrique
Widget _buildMetricItem(String title, String value, IconData icon, Color color) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: color.withOpacity(0.1)),
),
child: Row(
children: [
Icon(icon, color: color, size: 20),
const SizedBox(width: 12),
Expanded(
child: Text(
title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1F2937),
),
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(8),
),
child: Text(
value,
style: const TextStyle(
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
),
],
),
);
}
/// Élément d'alerte
Widget _buildAlertItem(String title, String subtitle, bool enabled, Color color) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: enabled ? color.withOpacity(0.05) : Colors.grey[50],
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: enabled ? color.withOpacity(0.3) : Colors.grey[300]!,
),
),
child: Row(
children: [
Icon(
enabled ? Icons.notifications_active : Icons.notifications_off,
color: enabled ? color : Colors.grey[600],
size: 20,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: enabled ? color : Colors.grey[700],
),
),
Text(
subtitle,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
),
],
),
),
Switch(
value: enabled,
onChanged: (value) => _showSuccessSnackBar('Alerte ${value ? 'activée' : 'désactivée'}'),
activeColor: color,
),
],
),
);
}
/// Élément de log
Widget _buildLogItem(String title, String count, Color color) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: color.withOpacity(0.1)),
),
child: Row(
children: [
Icon(Icons.circle, color: color, size: 12),
const SizedBox(width: 12),
Expanded(
child: Text(
title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1F2937),
),
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(12),
),
child: Text(
count,
style: const TextStyle(
fontSize: 11,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
),
],
),
);
}
/// Élément de statistique
Widget _buildStatItem(String title, String value) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
const Icon(Icons.bar_chart, color: ColorTokens.primary, size: 20),
const SizedBox(width: SpacingTokens.lg),
Expanded(
child: Text(
title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1F2937),
),
),
),
Text(
value,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
fontWeight: FontWeight.w600,
),
),
],
),
);
}
// ==================== MÉTHODES D'ACTION ====================
/// Charger les paramètres système
void _loadSystemSettings() {
// Simuler le chargement des paramètres depuis le serveur
// En production, ceci ferait appel à l'API
}
/// Afficher l'état du système
void _showSystemStatus() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('État du système'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildStatusItem('Serveur API', 'Opérationnel', Colors.green),
_buildStatusItem('Base de données', 'Opérationnel', Colors.green),
_buildStatusItem('Authentification', 'Opérationnel', Colors.green),
_buildStatusItem('CDN', 'Dégradé', Colors.orange),
_buildStatusItem('Monitoring', 'Opérationnel', Colors.green),
],
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Fermer'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
_showSuccessSnackBar('État du système actualisé');
},
style: ElevatedButton.styleFrom(
backgroundColor: ColorTokens.primary,
foregroundColor: ColorTokens.onPrimary,
),
child: const Text('Actualiser'),
),
],
),
);
}
/// Élément de statut
Widget _buildStatusItem(String service, String status, Color color) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
Icon(Icons.circle, color: color, size: 12),
const SizedBox(width: 8),
Expanded(child: Text(service)),
Text(
status,
style: TextStyle(
color: color,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
/// Exporter la configuration système
void _exportSystemConfig() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Exporter la configuration'),
content: const Text(
'La configuration système sera exportée dans un fichier JSON. '
'Ce fichier contient tous les paramètres actuels du système.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Annuler'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
_showSuccessSnackBar('Configuration exportée avec succès');
},
style: ElevatedButton.styleFrom(
backgroundColor: ColorTokens.primary,
foregroundColor: ColorTokens.onPrimary,
),
child: const Text('Exporter'),
),
],
),
);
}
/// Dialogue de mode maintenance
void _showMaintenanceModeDialog(bool enabled) {
if (enabled) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Mode maintenance activé'),
content: const Text(
'ATTENTION : Le mode maintenance va bloquer l\'accès à tous les utilisateurs. '
'Seuls les administrateurs système pourront accéder à l\'application.',
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
setState(() => _maintenanceMode = false);
},
child: const Text('Annuler'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
_showSuccessSnackBar('Mode maintenance activé - Utilisateurs bloqués');
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.orange,
foregroundColor: Colors.white,
),
child: const Text('Confirmer'),
),
],
),
);
} else {
_showSuccessSnackBar('Mode maintenance désactivé - Accès restauré');
}
}
// Actions générales
void _clearSystemCache() => _showSuccessSnackBar('Cache système vidé (2.3 GB libérés)');
void _optimizeDatabase() => _showSuccessSnackBar('Base de données optimisée');
void _testConnectivity() => _showSuccessSnackBar('Connectivité OK - Tous les services répondent');
// Actions de sécurité
void _regenerateApiKeys() => _showWarningDialog('Régénérer les clés API', 'Cette action invalidera toutes les clés existantes.');
void _forceGlobalLogout() => _showWarningDialog('Déconnexion globale', 'Tous les utilisateurs seront déconnectés immédiatement.');
void _resetSessions() => _showSuccessSnackBar('Sessions expirées nettoyées');
void _generateAuditReport() => _showSuccessSnackBar('Rapport d\'audit généré et envoyé par email');
void _exportGDPRData() => _showSuccessSnackBar('Export RGPD lancé - Vous recevrez un email');
void _purgeExpiredData() => _showWarningDialog('Purge des données', 'Les données expirées seront définitivement supprimées.');
// Actions de performance
void _analyzePerformance() => _showSuccessSnackBar('Analyse des performances lancée');
void _cleanOldLogs() => _showSuccessSnackBar('Logs anciens supprimés (450 MB libérés)');
void _restartServices() => _showWarningDialog('Redémarrer les services', 'Cette action causera une interruption temporaire.');
// Actions de maintenance
void _createBackup() => _showSuccessSnackBar('Sauvegarde créée avec succès');
void _restoreFromBackup() => _showWarningDialog('Restaurer une sauvegarde', 'Cette action remplacera toutes les données actuelles.');
void _scheduleMaintenance() => _showSuccessSnackBar('Fenêtre de maintenance programmée');
void _emergencyMaintenance() => _showWarningDialog('Maintenance d\'urgence', 'Le système sera immédiatement mis en maintenance.');
void _checkUpdates() => _showSuccessSnackBar('Aucune mise à jour disponible');
void _showUpdateHistory() => _showSuccessSnackBar('Historique des mises à jour affiché');
// Actions de monitoring
void _viewAllLogs() => _showSuccessSnackBar('Console de logs ouverte');
void _exportLogs() => _showSuccessSnackBar('Logs exportés pour analyse');
void _generateUsageReport() => _showSuccessSnackBar('Rapport d\'utilisation généré');
/// Dialogue d'avertissement générique
void _showWarningDialog(String title, String message) {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: Text(message),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Annuler'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
_showSuccessSnackBar('Action exécutée avec succès');
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red,
foregroundColor: Colors.white,
),
child: const Text('Confirmer'),
),
],
),
);
}
/// Afficher un message de succès
void _showSuccessSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: const Color(0xFF00B894),
behavior: SnackBarBehavior.floating,
),
);
}
/// Afficher un message d'erreur
void _showErrorSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: const Color(0xFFE74C3C),
behavior: SnackBarBehavior.floating,
),
);
}
}