Initial commit: Eventify frontend
This commit is contained in:
36
lib/features/auth/models/user_model.dart
Normal file
36
lib/features/auth/models/user_model.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
class UserModel {
|
||||
final String username;
|
||||
final String email;
|
||||
final String role;
|
||||
final String token;
|
||||
final String? phoneNumber;
|
||||
|
||||
UserModel({
|
||||
required this.username,
|
||||
required this.email,
|
||||
required this.role,
|
||||
required this.token,
|
||||
this.phoneNumber,
|
||||
});
|
||||
|
||||
/// Defensive factory: uses defaults when keys are missing
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
username: (json['username'] ?? json['email'] ?? '').toString(),
|
||||
email: (json['email'] ?? '').toString(),
|
||||
role: (json['role'] ?? 'user').toString(),
|
||||
token: (json['token'] ?? '').toString(),
|
||||
phoneNumber: json['phone_number'] != null ? json['phone_number'].toString() : null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'username': username,
|
||||
'email': email,
|
||||
'role': role,
|
||||
'token': token,
|
||||
if (phoneNumber != null) 'phone_number': phoneNumber,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user