Files
TravelMate/lib/models/user.dart
Dayron ec0bc59a70 feat: Integrate Firebase Authentication and Firestore
- Added Firebase configuration to Android and iOS projects.
- Created `google-services.json` and `GoogleService-Info.plist` for Firebase setup.
- Implemented `AuthService` for handling user authentication with Firebase.
- Updated `UserProvider` to manage user data with Firestore.
- Refactored `ProfileContent`, `LoginPage`, and `SignUpPage` to use the new authentication service.
- Removed the old `UserService` and replaced it with Firestore-based user management.
- Added Firebase options in `firebase_options.dart` for platform-specific configurations.
- Updated dependencies in `pubspec.yaml` for Firebase packages.
2025-10-06 18:57:30 +02:00

80 lines
1.7 KiB
Dart

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<String, dynamic> 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<String, dynamic> map = json.decode(jsonStr);
return User.fromMap(map);
}
// Méthode pour convertir un User en Map (utile pour Firebase)
Map<String, dynamic> 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;
}