Clean project: remove test files, debug logs, and add documentation
This commit is contained in:
@@ -0,0 +1,360 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Carte de performance système réutilisable
|
||||
///
|
||||
/// Widget spécialisé pour afficher les métriques de performance
|
||||
/// avec barres de progression et indicateurs colorés.
|
||||
class PerformanceCard extends StatelessWidget {
|
||||
/// Titre de la carte
|
||||
final String title;
|
||||
|
||||
/// Sous-titre optionnel
|
||||
final String? subtitle;
|
||||
|
||||
/// Liste des métriques de performance
|
||||
final List<PerformanceMetric> metrics;
|
||||
|
||||
/// Style de la carte
|
||||
final PerformanceCardStyle style;
|
||||
|
||||
/// Callback lors du tap sur la carte
|
||||
final VoidCallback? onTap;
|
||||
|
||||
/// Afficher ou non les valeurs numériques
|
||||
final bool showValues;
|
||||
|
||||
/// Afficher ou non les barres de progression
|
||||
final bool showProgressBars;
|
||||
|
||||
const PerformanceCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
required this.metrics,
|
||||
this.style = PerformanceCardStyle.elevated,
|
||||
this.onTap,
|
||||
this.showValues = true,
|
||||
this.showProgressBars = true,
|
||||
});
|
||||
|
||||
/// Constructeur pour les métriques serveur
|
||||
const PerformanceCard.server({
|
||||
super.key,
|
||||
this.onTap,
|
||||
}) : title = 'Performance Serveur',
|
||||
subtitle = 'Métriques temps réel',
|
||||
metrics = const [
|
||||
PerformanceMetric(
|
||||
label: 'CPU',
|
||||
value: 67.3,
|
||||
unit: '%',
|
||||
color: Colors.orange,
|
||||
threshold: 80,
|
||||
),
|
||||
PerformanceMetric(
|
||||
label: 'RAM',
|
||||
value: 78.5,
|
||||
unit: '%',
|
||||
color: Colors.blue,
|
||||
threshold: 85,
|
||||
),
|
||||
PerformanceMetric(
|
||||
label: 'Disque',
|
||||
value: 45.2,
|
||||
unit: '%',
|
||||
color: Colors.green,
|
||||
threshold: 90,
|
||||
),
|
||||
],
|
||||
style = PerformanceCardStyle.elevated,
|
||||
showValues = true,
|
||||
showProgressBars = true;
|
||||
|
||||
/// Constructeur pour les métriques réseau
|
||||
const PerformanceCard.network({
|
||||
super.key,
|
||||
this.onTap,
|
||||
}) : title = 'Réseau',
|
||||
subtitle = 'Trafic et latence',
|
||||
metrics = const [
|
||||
PerformanceMetric(
|
||||
label: 'Bande passante',
|
||||
value: 23.4,
|
||||
unit: 'MB/s',
|
||||
color: Color(0xFF6C5CE7),
|
||||
threshold: 100,
|
||||
),
|
||||
PerformanceMetric(
|
||||
label: 'Latence',
|
||||
value: 12.7,
|
||||
unit: 'ms',
|
||||
color: Color(0xFF00B894),
|
||||
threshold: 50,
|
||||
),
|
||||
PerformanceMetric(
|
||||
label: 'Paquets perdus',
|
||||
value: 0.02,
|
||||
unit: '%',
|
||||
color: Colors.red,
|
||||
threshold: 1,
|
||||
),
|
||||
],
|
||||
style = PerformanceCardStyle.elevated,
|
||||
showValues = true,
|
||||
showProgressBars = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: _getDecoration(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildHeader(),
|
||||
const SizedBox(height: 12),
|
||||
_buildMetrics(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// En-tête de la carte
|
||||
Widget _buildHeader() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF6C5CE7),
|
||||
),
|
||||
),
|
||||
if (subtitle != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Construction des métriques
|
||||
Widget _buildMetrics() {
|
||||
return Column(
|
||||
children: metrics.map((metric) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: _buildMetricRow(metric),
|
||||
)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Ligne de métrique
|
||||
Widget _buildMetricRow(PerformanceMetric metric) {
|
||||
final isWarning = metric.value > metric.threshold * 0.8;
|
||||
final isCritical = metric.value > metric.threshold;
|
||||
|
||||
Color effectiveColor = metric.color;
|
||||
if (isCritical) {
|
||||
effectiveColor = Colors.red;
|
||||
} else if (isWarning) {
|
||||
effectiveColor = Colors.orange;
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: effectiveColor,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
metric.label,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (showValues)
|
||||
Text(
|
||||
'${metric.value.toStringAsFixed(1)}${metric.unit}',
|
||||
style: TextStyle(
|
||||
color: effectiveColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (showProgressBars) ...[
|
||||
const SizedBox(height: 4),
|
||||
_buildProgressBar(metric, effectiveColor),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Barre de progression
|
||||
Widget _buildProgressBar(PerformanceMetric metric, Color color) {
|
||||
final progress = (metric.value / metric.threshold).clamp(0.0, 1.0);
|
||||
|
||||
return Container(
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[200],
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: progress,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Décoration selon le style
|
||||
BoxDecoration _getDecoration() {
|
||||
switch (style) {
|
||||
case PerformanceCardStyle.elevated:
|
||||
return BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
);
|
||||
case PerformanceCardStyle.outlined:
|
||||
return BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: const Color(0xFF6C5CE7).withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
);
|
||||
case PerformanceCardStyle.minimal:
|
||||
return BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Modèle de données pour une métrique de performance
|
||||
class PerformanceMetric {
|
||||
final String label;
|
||||
final double value;
|
||||
final String unit;
|
||||
final Color color;
|
||||
final double threshold;
|
||||
final Map<String, dynamic>? metadata;
|
||||
|
||||
const PerformanceMetric({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.unit,
|
||||
required this.color,
|
||||
required this.threshold,
|
||||
this.metadata,
|
||||
});
|
||||
|
||||
/// Constructeur pour une métrique CPU
|
||||
const PerformanceMetric.cpu(double value)
|
||||
: label = 'CPU',
|
||||
value = value,
|
||||
unit = '%',
|
||||
color = Colors.orange,
|
||||
threshold = 80,
|
||||
metadata = null;
|
||||
|
||||
/// Constructeur pour une métrique RAM
|
||||
const PerformanceMetric.memory(double value)
|
||||
: label = 'Mémoire',
|
||||
value = value,
|
||||
unit = '%',
|
||||
color = Colors.blue,
|
||||
threshold = 85,
|
||||
metadata = null;
|
||||
|
||||
/// Constructeur pour une métrique disque
|
||||
const PerformanceMetric.disk(double value)
|
||||
: label = 'Disque',
|
||||
value = value,
|
||||
unit = '%',
|
||||
color = Colors.green,
|
||||
threshold = 90,
|
||||
metadata = null;
|
||||
|
||||
/// Constructeur pour une métrique réseau
|
||||
PerformanceMetric.network(double value, String unit)
|
||||
: label = 'Réseau',
|
||||
value = value,
|
||||
unit = unit,
|
||||
color = const Color(0xFF6C5CE7),
|
||||
threshold = 100,
|
||||
metadata = null;
|
||||
|
||||
/// Niveau de criticité de la métrique
|
||||
MetricLevel get level {
|
||||
if (value > threshold) return MetricLevel.critical;
|
||||
if (value > threshold * 0.8) return MetricLevel.warning;
|
||||
if (value > threshold * 0.6) return MetricLevel.normal;
|
||||
return MetricLevel.good;
|
||||
}
|
||||
|
||||
/// Couleur selon le niveau
|
||||
Color get levelColor {
|
||||
switch (level) {
|
||||
case MetricLevel.good:
|
||||
return Colors.green;
|
||||
case MetricLevel.normal:
|
||||
return color;
|
||||
case MetricLevel.warning:
|
||||
return Colors.orange;
|
||||
case MetricLevel.critical:
|
||||
return Colors.red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Niveaux de métrique
|
||||
enum MetricLevel {
|
||||
good,
|
||||
normal,
|
||||
warning,
|
||||
critical,
|
||||
}
|
||||
|
||||
/// Styles de carte de performance
|
||||
enum PerformanceCardStyle {
|
||||
elevated,
|
||||
outlined,
|
||||
minimal,
|
||||
}
|
||||
Reference in New Issue
Block a user