58 lines
1.7 KiB
Dart
58 lines
1.7 KiB
Dart
abstract class User {
|
|
String? id;
|
|
String name;
|
|
String? photo;
|
|
bool gender; // true for male, false for female
|
|
DateTime? birthday;
|
|
String? phoneNumber;
|
|
// String email;
|
|
String? note;
|
|
DateTime? createTime;
|
|
DateTime? lastUpdateTime;
|
|
|
|
User({
|
|
this.id,
|
|
required this.name,
|
|
this.photo,
|
|
required this.gender,
|
|
required this.birthday,
|
|
required this.phoneNumber,
|
|
// required this.email,
|
|
this.note,
|
|
required this.createTime,
|
|
required this.lastUpdateTime,
|
|
});
|
|
|
|
// Named constructor from JSON
|
|
User.fromJson(Map<String, dynamic> json)
|
|
: id = json['_id'] as String?,
|
|
name = json['name'] as String,
|
|
photo = json['photo'] as String?,
|
|
gender = json['gender'] as bool,
|
|
birthday = json['birthday'] == null
|
|
? null
|
|
: DateTime.parse(json['birthday'] as String).toLocal(),
|
|
phoneNumber = json['phoneNumber'] as String?,
|
|
// email = json['email'] as String,
|
|
note = json['note'] as String?,
|
|
createTime = json['createTime'] == null
|
|
? null
|
|
: DateTime.parse(json['createTime'] as String).toLocal(),
|
|
lastUpdateTime = json['lastUpdateTime'] == null
|
|
? null
|
|
: DateTime.parse(json['lastUpdateTime'] as String).toLocal();
|
|
|
|
// Method to convert to JSON
|
|
Map<String, dynamic> toJson() => {
|
|
'_id': id,
|
|
'name': name,
|
|
'photo': photo,
|
|
'gender': gender,
|
|
'birthday': birthday?.toUtc().toIso8601String(),
|
|
'phoneNumber': phoneNumber,
|
|
'note': note,
|
|
'createTime': createTime?.toUtc().toIso8601String(),
|
|
'lastUpdateTime': lastUpdateTime?.toUtc().toIso8601String(),
|
|
};
|
|
}
|