feat: Enhance trip creation and management features with user validation, improved error handling, and Firestore integration

This commit is contained in:
Dayron
2025-10-07 11:38:20 +02:00
parent c90011ef5d
commit 4e403f3308
5 changed files with 625 additions and 225 deletions

View File

@@ -36,17 +36,51 @@ class Trip {
title: map['title'] ?? '',
description: map['description'] ?? '',
location: map['location'] ?? '',
startDate: DateTime.fromMillisecondsSinceEpoch(map['startDate']),
endDate: DateTime.fromMillisecondsSinceEpoch(map['endDate']),
startDate: _parseDateTime(map['startDate']),
endDate: _parseDateTime(map['endDate']),
budget: map['budget']?.toDouble(),
participants: List<String>.from(map['participants'] ?? []),
createdBy: map['createdBy'] ?? '',
createdAt: DateTime.fromMillisecondsSinceEpoch(map['createdAt']),
updatedAt: DateTime.fromMillisecondsSinceEpoch(map['updatedAt']),
createdAt: _parseDateTime(map['createdAt']),
updatedAt: _parseDateTime(map['updatedAt']),
status: map['status'] ?? 'draft',
);
}
// Méthode helper pour parser les dates depuis différents formats
static DateTime _parseDateTime(dynamic dateValue) {
if (dateValue == null) {
return DateTime.now();
}
if (dateValue is DateTime) {
return dateValue;
}
if (dateValue is String) {
try {
// Essayer de parser comme ISO 8601
return DateTime.parse(dateValue);
} catch (e) {
print('Erreur parsing date string: $dateValue - $e');
return DateTime.now();
}
}
if (dateValue is int) {
try {
// Traiter comme millisecondes
return DateTime.fromMillisecondsSinceEpoch(dateValue);
} catch (e) {
print('Erreur parsing date int: $dateValue - $e');
return DateTime.now();
}
}
print('Type de date non supporté: ${dateValue.runtimeType} - $dateValue');
return DateTime.now();
}
// Constructeur pour créer un Trip depuis JSON
factory Trip.fromJson(String jsonStr) {
Map<String, dynamic> map = json.decode(jsonStr);