Initial commit
This commit is contained in:
69
lib/models/user.dart
Normal file
69
lib/models/user.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
enum UserRole { boss, employee }
|
||||
|
||||
class User {
|
||||
final String id;
|
||||
final String phone;
|
||||
final String name;
|
||||
final String avatar;
|
||||
final UserRole role;
|
||||
final String token;
|
||||
final String? hotelName;
|
||||
final String? scenicName;
|
||||
|
||||
const User({
|
||||
required this.id,
|
||||
required this.phone,
|
||||
required this.name,
|
||||
required this.avatar,
|
||||
required this.role,
|
||||
required this.token,
|
||||
this.hotelName,
|
||||
this.scenicName,
|
||||
});
|
||||
|
||||
bool get isBoss => role == UserRole.boss;
|
||||
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? phone,
|
||||
String? name,
|
||||
String? avatar,
|
||||
UserRole? role,
|
||||
String? token,
|
||||
String? hotelName,
|
||||
String? scenicName,
|
||||
}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
phone: phone ?? this.phone,
|
||||
name: name ?? this.name,
|
||||
avatar: avatar ?? this.avatar,
|
||||
role: role ?? this.role,
|
||||
token: token ?? this.token,
|
||||
hotelName: hotelName ?? this.hotelName,
|
||||
scenicName: scenicName ?? this.scenicName,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'phone': phone,
|
||||
'name': name,
|
||||
'avatar': avatar,
|
||||
'role': role.name,
|
||||
'token': token,
|
||||
'hotelName': hotelName,
|
||||
'scenicName': scenicName,
|
||||
};
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) => User(
|
||||
id: json['id'] ?? '',
|
||||
phone: json['phone'] ?? '',
|
||||
name: json['name'] ?? '',
|
||||
avatar: json['avatar'] ?? '',
|
||||
role: UserRole.values.byName(json['role'] ?? 'employee'),
|
||||
token: json['token'] ?? '',
|
||||
hotelName: json['hotelName'],
|
||||
scenicName: json['scenicName'],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user