2022-04-24 04:08:45 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2022-06-18 17:56:36 +02:00
|
|
|
class User {
|
2022-04-24 04:08:45 +02:00
|
|
|
final String id;
|
|
|
|
final String email;
|
|
|
|
final String createdAt;
|
2022-06-18 17:56:36 +02:00
|
|
|
final String firstName;
|
|
|
|
final String lastName;
|
2022-04-24 04:08:45 +02:00
|
|
|
|
2022-06-18 17:56:36 +02:00
|
|
|
User({
|
2022-04-24 04:08:45 +02:00
|
|
|
required this.id,
|
|
|
|
required this.email,
|
|
|
|
required this.createdAt,
|
2022-06-18 17:56:36 +02:00
|
|
|
required this.firstName,
|
|
|
|
required this.lastName,
|
2022-04-24 04:08:45 +02:00
|
|
|
});
|
|
|
|
|
2022-06-18 17:56:36 +02:00
|
|
|
User copyWith({
|
2022-04-24 04:08:45 +02:00
|
|
|
String? id,
|
|
|
|
String? email,
|
|
|
|
String? createdAt,
|
2022-06-18 17:56:36 +02:00
|
|
|
String? firstName,
|
|
|
|
String? lastName,
|
2022-04-24 04:08:45 +02:00
|
|
|
}) {
|
2022-06-18 17:56:36 +02:00
|
|
|
return User(
|
2022-04-24 04:08:45 +02:00
|
|
|
id: id ?? this.id,
|
|
|
|
email: email ?? this.email,
|
|
|
|
createdAt: createdAt ?? this.createdAt,
|
2022-06-18 17:56:36 +02:00
|
|
|
firstName: firstName ?? this.firstName,
|
|
|
|
lastName: lastName ?? this.lastName,
|
2022-04-24 04:08:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
final result = <String, dynamic>{};
|
|
|
|
|
|
|
|
result.addAll({'id': id});
|
|
|
|
result.addAll({'email': email});
|
|
|
|
result.addAll({'createdAt': createdAt});
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-06-18 17:56:36 +02:00
|
|
|
factory User.fromMap(Map<String, dynamic> map) {
|
|
|
|
return User(
|
2022-04-24 04:08:45 +02:00
|
|
|
id: map['id'] ?? '',
|
|
|
|
email: map['email'] ?? '',
|
|
|
|
createdAt: map['createdAt'] ?? '',
|
2022-06-18 17:56:36 +02:00
|
|
|
firstName: map['firstName'] ?? '',
|
|
|
|
lastName: map['lastName'] ?? '',
|
2022-04-24 04:08:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
2022-06-18 17:56:36 +02:00
|
|
|
factory User.fromJson(String source) => User.fromMap(json.decode(source));
|
2022-04-24 04:08:45 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => 'UserInfo(id: $id, email: $email, createdAt: $createdAt)';
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
|
2022-06-18 17:56:36 +02:00
|
|
|
return other is User &&
|
|
|
|
other.id == id &&
|
|
|
|
other.email == email &&
|
|
|
|
other.createdAt == createdAt &&
|
|
|
|
other.firstName == firstName &&
|
|
|
|
other.lastName == lastName;
|
2022-04-24 04:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode => id.hashCode ^ email.hashCode ^ createdAt.hashCode;
|
|
|
|
}
|