feat: updated container management system with core models, providers, and UI pages

This commit is contained in:
ElPoyo
2026-05-26 21:34:35 +02:00
parent fb740d97a3
commit 64a9fe382a
13 changed files with 1363 additions and 797 deletions
+45 -21
View File
@@ -387,40 +387,64 @@ class EquipmentModel {
});
factory EquipmentModel.fromMap(Map<String, dynamic> map, String id) {
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
// Fonction helper pour convertir de manière sécurisée en double
double? parseDouble(dynamic value) {
if (value == null) return null;
if (value is num) return value.toDouble();
if (value is String) return double.tryParse(value);
return null;
}
// Fonction helper pour convertir de manière sécurisée en int
int? parseInt(dynamic value) {
if (value == null) return null;
if (value is num) return value.toInt();
if (value is String) return int.tryParse(value);
return null;
}
// Fonction helper pour convertir Timestamp ou String ISO ou int epoch en DateTime
DateTime? parseDate(dynamic value) {
if (value == null) return null;
if (value is Timestamp) return value.toDate();
if (value is String) return DateTime.tryParse(value);
if (value is int) return DateTime.fromMillisecondsSinceEpoch(value);
return null;
}
// Gestion des listes
final List<dynamic> maintenanceIdsRaw = map['maintenanceIds'] ?? [];
final List<String> maintenanceIds = maintenanceIdsRaw.map((e) => e.toString()).toList();
// Gestion sécurisée des listes d'IDs de maintenance
final List<String> maintenanceIds = [];
if (map['maintenanceIds'] is List) {
for (final e in map['maintenanceIds'] as List) {
if (e != null) {
maintenanceIds.add(e.toString());
}
}
}
return EquipmentModel(
id: id,
name: map['name'] ?? '',
brand: map['brand'],
model: map['model'],
category: equipmentCategoryFromString(map['category']),
subCategory: map['subCategory'],
status: equipmentStatusFromString(map['status']),
purchasePrice: map['purchasePrice']?.toDouble(),
rentalPrice: map['rentalPrice']?.toDouble(),
totalQuantity: map['totalQuantity']?.toInt(),
availableQuantity: map['availableQuantity']?.toInt(),
criticalThreshold: map['criticalThreshold']?.toInt(),
weight: map['weight']?.toDouble(),
length: map['length']?.toDouble(),
width: map['width']?.toDouble(),
height: map['height']?.toDouble(),
name: (map['name'] ?? '').toString(),
brand: map['brand']?.toString(),
model: map['model']?.toString(),
category: equipmentCategoryFromString(map['category']?.toString()),
subCategory: map['subCategory']?.toString(),
status: equipmentStatusFromString(map['status']?.toString()),
purchasePrice: parseDouble(map['purchasePrice']),
rentalPrice: parseDouble(map['rentalPrice']),
totalQuantity: parseInt(map['totalQuantity']),
availableQuantity: parseInt(map['availableQuantity']),
criticalThreshold: parseInt(map['criticalThreshold']),
weight: parseDouble(map['weight']),
length: parseDouble(map['length']),
width: parseDouble(map['width']),
height: parseDouble(map['height']),
purchaseDate: parseDate(map['purchaseDate']),
lastMaintenanceDate: parseDate(map['lastMaintenanceDate']),
nextMaintenanceDate: parseDate(map['nextMaintenanceDate']),
maintenanceIds: maintenanceIds,
imageUrl: map['imageUrl'],
notes: map['notes'],
imageUrl: map['imageUrl']?.toString(),
notes: map['notes']?.toString(),
createdAt: parseDate(map['createdAt']) ?? DateTime.now(),
updatedAt: parseDate(map['updatedAt']) ?? DateTime.now(),
);