1+ // ignore_for_file: public_member_api_docs, sort_constructors_first
2+ import 'dart:convert' ;
3+
14abstract interface class IPersonApiRepository {
25 Future <List <Person >> getAll ();
36 Future <Person > update (String id, {String ? name});
@@ -6,10 +9,10 @@ abstract interface class IPersonApiRepository {
69class Person {
710 Person ({
811 required this .id,
12+ this .birthDate,
913 required this .isHidden,
1014 required this .name,
1115 required this .thumbnailPath,
12- this .birthDate,
1316 this .updatedAt,
1417 });
1518
@@ -19,4 +22,80 @@ class Person {
1922 final String name;
2023 final String thumbnailPath;
2124 final DateTime ? updatedAt;
25+
26+ @override
27+ String toString () {
28+ return 'Person(id: $id , birthDate: $birthDate , isHidden: $isHidden , name: $name , thumbnailPath: $thumbnailPath , updatedAt: $updatedAt )' ;
29+ }
30+
31+ Person copyWith ({
32+ String ? id,
33+ DateTime ? birthDate,
34+ bool ? isHidden,
35+ String ? name,
36+ String ? thumbnailPath,
37+ DateTime ? updatedAt,
38+ }) {
39+ return Person (
40+ id: id ?? this .id,
41+ birthDate: birthDate ?? this .birthDate,
42+ isHidden: isHidden ?? this .isHidden,
43+ name: name ?? this .name,
44+ thumbnailPath: thumbnailPath ?? this .thumbnailPath,
45+ updatedAt: updatedAt ?? this .updatedAt,
46+ );
47+ }
48+
49+ Map <String , dynamic > toMap () {
50+ return < String , dynamic > {
51+ 'id' : id,
52+ 'birthDate' : birthDate? .millisecondsSinceEpoch,
53+ 'isHidden' : isHidden,
54+ 'name' : name,
55+ 'thumbnailPath' : thumbnailPath,
56+ 'updatedAt' : updatedAt? .millisecondsSinceEpoch,
57+ };
58+ }
59+
60+ factory Person .fromMap (Map <String , dynamic > map) {
61+ return Person (
62+ id: map['id' ] as String ,
63+ birthDate: map['birthDate' ] != null
64+ ? DateTime .fromMillisecondsSinceEpoch (map['birthDate' ] as int )
65+ : null ,
66+ isHidden: map['isHidden' ] as bool ,
67+ name: map['name' ] as String ,
68+ thumbnailPath: map['thumbnailPath' ] as String ,
69+ updatedAt: map['updatedAt' ] != null
70+ ? DateTime .fromMillisecondsSinceEpoch (map['updatedAt' ] as int )
71+ : null ,
72+ );
73+ }
74+
75+ String toJson () => json.encode (toMap ());
76+
77+ factory Person .fromJson (String source) =>
78+ Person .fromMap (json.decode (source) as Map <String , dynamic >);
79+
80+ @override
81+ bool operator == (covariant Person other) {
82+ if (identical (this , other)) return true ;
83+
84+ return other.id == id &&
85+ other.birthDate == birthDate &&
86+ other.isHidden == isHidden &&
87+ other.name == name &&
88+ other.thumbnailPath == thumbnailPath &&
89+ other.updatedAt == updatedAt;
90+ }
91+
92+ @override
93+ int get hashCode {
94+ return id.hashCode ^
95+ birthDate.hashCode ^
96+ isHidden.hashCode ^
97+ name.hashCode ^
98+ thumbnailPath.hashCode ^
99+ updatedAt.hashCode;
100+ }
22101}
0 commit comments