class EventModel { final String eventId; final String title; final String description; final String eventDate; final String location; final String category; final String? link; final String? imageUrl; final String creatorId; EventModel({ required this.eventId, required this.title, required this.description, required this.eventDate, required this.location, required this.category, this.link, this.imageUrl, required this.creatorId, }); // Méthode pour créer un EventModel à partir d'un JSON factory EventModel.fromJson(Map json) { return EventModel( eventId: json['id'], title: json['title'], description: json['description'], eventDate: json['event_date'], location: json['location'], category: json['category'], link: json['link'], imageUrl: json['imageUrl'], creatorId: json['creator']['id'], // Assurez-vous que le JSON a ce format ); } // Méthode pour convertir un EventModel en JSON Map toJson() { return { 'id': eventId, 'title': title, 'description': description, 'event_date': eventDate, 'location': location, 'category': category, 'link': link, 'imageUrl': imageUrl, 'creator': {'id': creatorId}, // Structure du JSON pour l'API }; } // Convertir une liste d'EventModel à partir d'une liste JSON static List fromJsonList(List jsonList) { return jsonList.map((json) => EventModel.fromJson(json)).toList(); } // Convertir une liste d'EventModel en JSON static List> toJsonList(List events) { return events.map((event) => event.toJson()).toList(); } }