import 'dart:convert'; class User { final String? id; final String nom; final String prenom; final String email; User({ this.id, required this.nom, required this.prenom, required this.email, }); // Constructeur pour créer un User depuis un Map (utile pour Firebase) factory User.fromMap(Map map) { return User( id: map['id'], nom: map['nom'] ?? '', prenom: map['prenom'] ?? '', email: map['email'] ?? '', ); } // Constructeur pour créer un User depuis JSON factory User.fromJson(String jsonStr) { Map map = json.decode(jsonStr); return User.fromMap(map); } // Méthode pour convertir un User en Map (utile pour Firebase) Map toMap() { return { 'id': id, 'nom': nom, 'prenom': prenom, 'email': email, }; } // Méthode pour convertir un User en JSON String toJson() { return json.encode(toMap()); } // Méthode pour obtenir le nom complet String get fullName => '$prenom $nom'; // Méthode pour créer une copie avec des modifications User copyWith({ String? id, String? nom, String? prenom, String? email, }) { return User( id: id ?? this.id, nom: nom ?? this.nom, prenom: prenom ?? this.prenom, email: email ?? this.email, ); } @override String toString() { return 'User(id: $id, nom: $nom, prenom: $prenom, email: $email)'; } @override bool operator ==(Object other) { if (identical(this, other)) return true; return other is User && other.email == email; } @override int get hashCode => email.hashCode; }