Refactor: Centralisation des labels et icônes pour les enums
Centralise la gestion des libellés, couleurs et icônes pour `EquipmentStatus`, `EquipmentCategory`, et `ContainerType` en utilisant des extensions Dart. - Ajout de nouvelles icônes SVG pour `flight-case`, `truss` et `tape`. - Refactorisation des vues pour utiliser les nouvelles extensions, supprimant ainsi la logique d'affichage dupliquée. - Mise à jour des `ChoiceChip` et des listes de filtres pour afficher les icônes à côté des labels.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:em2rp/models/equipment_model.dart';
|
||||
|
||||
/// Type de container
|
||||
@@ -57,6 +59,119 @@ String containerTypeLabel(ContainerType type) {
|
||||
}
|
||||
}
|
||||
|
||||
// Extensions pour centraliser les informations d'affichage
|
||||
extension ContainerTypeExtension on ContainerType {
|
||||
/// Retourne le label français du type de container
|
||||
String get label {
|
||||
switch (this) {
|
||||
case ContainerType.flightCase:
|
||||
return 'Flight Case';
|
||||
case ContainerType.pelicase:
|
||||
return 'Pelicase';
|
||||
case ContainerType.bag:
|
||||
return 'Sac';
|
||||
case ContainerType.openCrate:
|
||||
return 'Caisse Ouverte';
|
||||
case ContainerType.toolbox:
|
||||
return 'Boîte à Outils';
|
||||
}
|
||||
}
|
||||
|
||||
/// Retourne l'icône Material du type de container
|
||||
IconData get iconData {
|
||||
switch (this) {
|
||||
case ContainerType.flightCase:
|
||||
return Icons.work;
|
||||
case ContainerType.pelicase:
|
||||
return Icons.inventory_2;
|
||||
case ContainerType.bag:
|
||||
return Icons.shopping_bag;
|
||||
case ContainerType.openCrate:
|
||||
return Icons.inventory;
|
||||
case ContainerType.toolbox:
|
||||
return Icons.build_circle;
|
||||
}
|
||||
}
|
||||
|
||||
/// Retourne le chemin de l'icône personnalisée (si disponible)
|
||||
String? get customIconPath {
|
||||
switch (this) {
|
||||
case ContainerType.flightCase:
|
||||
return 'assets/icons/flight-case.svg';
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Vérifie si une icône personnalisée est disponible
|
||||
bool get hasCustomIcon => customIconPath != null;
|
||||
|
||||
/// Retourne l'icône Widget à afficher (unifié pour Material et personnalisé)
|
||||
Widget getIcon({double size = 24, Color? color}) {
|
||||
final customPath = customIconPath;
|
||||
if (customPath != null) {
|
||||
// Détection automatique du format (SVG ou PNG)
|
||||
final isSvg = customPath.toLowerCase().endsWith('.svg');
|
||||
|
||||
if (isSvg) {
|
||||
// SVG : on peut appliquer la couleur sans dégrader la qualité
|
||||
return SvgPicture.asset(
|
||||
customPath,
|
||||
width: size,
|
||||
height: size,
|
||||
colorFilter: color != null
|
||||
? ColorFilter.mode(color, BlendMode.srcIn)
|
||||
: null,
|
||||
placeholderBuilder: (context) => Icon(iconData, size: size, color: color),
|
||||
);
|
||||
} else {
|
||||
// PNG : on n'applique PAS le color filter pour préserver la qualité
|
||||
return Image.asset(
|
||||
customPath,
|
||||
width: size,
|
||||
height: size,
|
||||
filterQuality: FilterQuality.high,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Icon(iconData, size: size, color: color);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
return Icon(iconData, size: size, color: color);
|
||||
}
|
||||
|
||||
/// Version pour CircleAvatar et contextes similaires
|
||||
Widget getIconForAvatar({double size = 24, Color? color}) {
|
||||
final customPath = customIconPath;
|
||||
if (customPath != null) {
|
||||
final isSvg = customPath.toLowerCase().endsWith('.svg');
|
||||
|
||||
if (isSvg) {
|
||||
return SvgPicture.asset(
|
||||
customPath,
|
||||
width: size,
|
||||
height: size,
|
||||
colorFilter: color != null
|
||||
? ColorFilter.mode(color, BlendMode.srcIn)
|
||||
: null,
|
||||
placeholderBuilder: (context) => Icon(iconData, size: size, color: color),
|
||||
);
|
||||
} else {
|
||||
return Image.asset(
|
||||
customPath,
|
||||
width: size,
|
||||
height: size,
|
||||
filterQuality: FilterQuality.high,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Icon(iconData, size: size, color: color);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
return Icon(iconData, size: size, color: color);
|
||||
}
|
||||
}
|
||||
|
||||
/// Modèle de container/boîte pour le matériel
|
||||
class ContainerModel {
|
||||
final String id; // Identifiant unique (généré comme pour équipement)
|
||||
|
||||
Reference in New Issue
Block a user