forked from TheAlphamerc/flutter_twitter_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.dart
157 lines (152 loc) · 3.99 KB
/
user.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
class UserModel {
String key;
String email;
String userId;
String displayName;
String userName;
String webSite;
String profilePic;
String bannerImage;
String contact;
String bio;
String location;
String dob;
String createdAt;
bool isVerified;
int followers;
int following;
String fcmToken;
List<String> followersList;
List<String> followingList;
UserModel(
{this.email,
this.userId,
this.displayName,
this.profilePic,
this.bannerImage,
this.key,
this.contact,
this.bio,
this.dob,
this.location,
this.createdAt,
this.userName,
this.followers,
this.following,
this.webSite,
this.isVerified,
this.fcmToken,
this.followersList,
this.followingList});
UserModel.fromJson(Map<dynamic, dynamic> map) {
if (map == null) {
return;
}
if (followersList == null) {
followersList = [];
}
email = map['email'];
userId = map['userId'];
displayName = map['displayName'];
profilePic = map['profilePic'];
bannerImage = map['bannerImage'];
key = map['key'];
dob = map['dob'];
bio = map['bio'];
location = map['location'];
contact = map['contact'];
createdAt = map['createdAt'];
followers = map['followers'];
following = map['following'];
userName = map['userName'];
webSite = map['webSite'];
fcmToken = map['fcmToken'];
isVerified = map['isVerified'] ?? false;
if (map['followerList'] != null) {
followersList = <String>[];
map['followerList'].forEach((value) {
followersList.add(value);
});
}
followers = followersList != null ? followersList.length : null;
if (map['followingList'] != null) {
followingList = <String>[];
map['followingList'].forEach((value) {
followingList.add(value);
});
}
following = followingList != null ? followingList.length : null;
}
toJson() {
return {
'key': key,
"userId": userId,
"email": email,
'displayName': displayName,
'profilePic': profilePic,
'bannerImage': bannerImage,
'contact': contact,
'dob': dob,
'bio': bio,
'location': location,
'createdAt': createdAt,
'followers': followersList != null ? followersList.length : null,
'following': followingList != null ? followingList.length : null,
'userName': userName,
'webSite': webSite,
'isVerified': isVerified ?? false,
'fcmToken': fcmToken,
'followerList': followersList,
'followingList': followingList
};
}
UserModel copyWith({
String email,
String userId,
String displayName,
String profilePic,
String key,
String contact,
bio,
String dob,
String bannerImage,
String location,
String createdAt,
String userName,
int followers,
int following,
String webSite,
bool isVerified,
String fcmToken,
List<String> followingList,
List<String> followersList,
}) {
return UserModel(
email: email ?? this.email,
bio: bio ?? this.bio,
contact: contact ?? this.contact,
createdAt: createdAt ?? this.createdAt,
displayName: displayName ?? this.displayName,
dob: dob ?? this.dob,
followers: followersList != null ? followersList.length : null,
following: following ?? this.following,
isVerified: isVerified ?? this.isVerified,
key: key ?? this.key,
location: location ?? this.location,
profilePic: profilePic ?? this.profilePic,
bannerImage: bannerImage ?? this.bannerImage,
userId: userId ?? this.userId,
userName: userName ?? this.userName,
webSite: webSite ?? this.webSite,
fcmToken: fcmToken ?? this.fcmToken,
followersList: followersList ?? this.followersList,
followingList: followingList ?? this.followingList,
);
}
String get getFollower {
return '${this.followers ?? 0}';
}
String get getFollowing {
return '${this.following ?? 0}';
}
}