Ajout des options
This commit is contained in:
		| @@ -7,7 +7,7 @@ class EventModel { | ||||
|   final String description; | ||||
|   final DateTime startDateTime; | ||||
|   final DateTime endDateTime; | ||||
|   final double price; | ||||
|   final double basePrice; | ||||
|   final int installationTime; | ||||
|   final int disassemblyTime; | ||||
|   final String eventTypeId; | ||||
| @@ -17,6 +17,7 @@ class EventModel { | ||||
|   final double longitude; | ||||
|   final List<DocumentReference> workforce; | ||||
|   final List<Map<String, String>> documents; | ||||
|   final List<Map<String, dynamic>> options; | ||||
|  | ||||
|   EventModel({ | ||||
|     required this.id, | ||||
| @@ -24,7 +25,7 @@ class EventModel { | ||||
|     required this.description, | ||||
|     required this.startDateTime, | ||||
|     required this.endDateTime, | ||||
|     required this.price, | ||||
|     required this.basePrice, | ||||
|     required this.installationTime, | ||||
|     required this.disassemblyTime, | ||||
|     required this.eventTypeId, | ||||
| @@ -34,6 +35,7 @@ class EventModel { | ||||
|     required this.longitude, | ||||
|     required this.workforce, | ||||
|     required this.documents, | ||||
|     this.options = const [], | ||||
|   }); | ||||
|  | ||||
|   factory EventModel.fromMap(Map<String, dynamic> map, String id) { | ||||
| @@ -55,6 +57,16 @@ class EventModel { | ||||
|             } | ||||
|           }).toList() | ||||
|         : <Map<String, String>>[]; | ||||
|     final optionsRaw = map['options'] ?? []; | ||||
|     final options = optionsRaw is List | ||||
|         ? optionsRaw.map<Map<String, dynamic>>((e) { | ||||
|             if (e is Map) { | ||||
|               return Map<String, dynamic>.from(e as Map); | ||||
|             } else { | ||||
|               return {}; | ||||
|             } | ||||
|           }).toList() | ||||
|         : <Map<String, dynamic>>[]; | ||||
|     return EventModel( | ||||
|       id: id, | ||||
|       name: map['Name'] ?? '', | ||||
| @@ -62,7 +74,7 @@ class EventModel { | ||||
|       startDateTime: startTimestamp?.toDate() ?? DateTime.now(), | ||||
|       endDateTime: endTimestamp?.toDate() ?? | ||||
|           DateTime.now().add(const Duration(hours: 1)), | ||||
|       price: (map['Price'] ?? 0.0).toDouble(), | ||||
|       basePrice: (map['BasePrice'] ?? map['Price'] ?? 0.0).toDouble(), | ||||
|       installationTime: map['InstallationTime'] ?? 0, | ||||
|       disassemblyTime: map['DisassemblyTime'] ?? 0, | ||||
|       eventTypeId: map['EventType'] is DocumentReference | ||||
| @@ -76,6 +88,7 @@ class EventModel { | ||||
|       longitude: (map['Longitude'] ?? 0.0).toDouble(), | ||||
|       workforce: workforceRefs.whereType<DocumentReference>().toList(), | ||||
|       documents: docs, | ||||
|       options: options, | ||||
|     ); | ||||
|   } | ||||
|  | ||||
| @@ -85,7 +98,7 @@ class EventModel { | ||||
|       'Description': description, | ||||
|       'StartDateTime': Timestamp.fromDate(startDateTime), | ||||
|       'EndDateTime': Timestamp.fromDate(endDateTime), | ||||
|       'Price': price, | ||||
|       'BasePrice': basePrice, | ||||
|       'InstallationTime': installationTime, | ||||
|       'DisassemblyTime': disassemblyTime, | ||||
|       'EventType': eventTypeId, | ||||
| @@ -96,6 +109,7 @@ class EventModel { | ||||
|       'Longitude': longitude, | ||||
|       'workforce': workforce, | ||||
|       'documents': documents, | ||||
|       'options': options, | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user