1
-
2
1
import 'package:flutter_twitter_clone/model/user.dart' ;
3
2
4
3
class FeedModel {
@@ -8,140 +7,104 @@ class FeedModel {
8
7
String description;
9
8
String userId;
10
9
int likeCount;
11
- List <LikeList > likeList;
10
+ List <String > likeList;
12
11
int commentCount;
13
12
int retweetCount;
14
13
String createdAt;
15
14
String imagePath;
16
15
List <String > tags;
17
16
List <String > replyTweetKeyList;
18
17
User user;
19
- FeedModel ({
20
- this .key,
21
- this .description,
22
- this .userId,
23
- this .likeCount,
24
- this .commentCount,
25
- this .retweetCount,
26
- this .createdAt,
27
- this .imagePath,
28
- this .likeList,
29
- this .tags,
30
- this .user,
31
- this .replyTweetKeyList,
32
- this .parentkey,
33
- this .childRetwetkey
34
- });
18
+ FeedModel (
19
+ {this .key,
20
+ this .description,
21
+ this .userId,
22
+ this .likeCount,
23
+ this .commentCount,
24
+ this .retweetCount,
25
+ this .createdAt,
26
+ this .imagePath,
27
+ this .likeList,
28
+ this .tags,
29
+ this .user,
30
+ this .replyTweetKeyList,
31
+ this .parentkey,
32
+ this .childRetwetkey});
35
33
toJson () {
36
- Map <dynamic ,dynamic > map;
37
- if (likeList != null && likeList.length > 0 ){
38
- map = Map .fromIterable (likeList, key: (v) => v.key, value: (v){
39
- var list = LikeList (key: v.key, userId: v.userId);
40
- return list.toJson ();
41
- });
42
- }
43
34
return {
44
35
"userId" : userId,
45
36
"description" : description,
46
- "likeCount" : likeCount,
47
- "commentCount" : commentCount ?? 0 ,
37
+ "likeCount" : likeCount,
38
+ "commentCount" : commentCount ?? 0 ,
48
39
"retweetCount" : retweetCount ?? 0 ,
49
- "createdAt" : createdAt,
50
- "imagePath" : imagePath,
51
- "likeList" : map ,
52
- "tags" : tags,
53
- "replyTweetKeyList" : replyTweetKeyList,
54
- "user" : user == null ? null : user.toJson (),
40
+ "createdAt" : createdAt,
41
+ "imagePath" : imagePath,
42
+ "likeList" : likeList ,
43
+ "tags" : tags,
44
+ "replyTweetKeyList" : replyTweetKeyList,
45
+ "user" : user == null ? null : user.toJson (),
55
46
"parentkey" : parentkey,
56
- "childRetwetkey" : childRetwetkey
47
+ "childRetwetkey" : childRetwetkey
57
48
};
58
49
}
59
- dynamic getLikeList (List <String > list){
60
- if (list != null && list.length > 0 ){
61
- var result = Map .fromIterable (list, key: (v) => 'userId' , value: (v) => v[0 ]);
62
- return result;
63
- }
64
- }
50
+
65
51
FeedModel .fromJson (Map <dynamic , dynamic > map) {
66
- if (likeList == null ){
52
+ key = map['key' ];
53
+ description = map['description' ];
54
+ userId = map['userId' ];
55
+ // name = map['name'];
56
+ // profilePic = map['profilePic'];
57
+ likeCount = map['likeCount' ];
58
+ commentCount = map['commentCount' ];
59
+ retweetCount = map["retweetCount" ] ?? 0 ;
60
+ imagePath = map['imagePath' ];
61
+ createdAt = map['createdAt' ];
62
+ imagePath = map['imagePath' ];
63
+ // username = map['username'];
64
+ user = User .fromJson (map['user' ]);
65
+ parentkey = map['parentkey' ];
66
+ childRetwetkey = map['childRetwetkey' ];
67
+ if (map['tags' ] != null ) {
68
+ tags = List <String >();
69
+ map['tags' ].forEach ((value) {
70
+ tags.add (value);
71
+ });
72
+ }
73
+ if (map["likeList" ] != null ) {
74
+ likeList = List <String >();
75
+ map['likeList' ].forEach ((value) {
76
+ likeList.add (value);
77
+ });
78
+ likeCount = likeList.length;
79
+ } else {
67
80
likeList = [];
81
+ likeCount = 0 ;
82
+ }
83
+ if (map['replyTweetKeyList' ] != null ) {
84
+ map['replyTweetKeyList' ].forEach ((value) {
85
+ replyTweetKeyList = List <String >();
86
+ map['replyTweetKeyList' ].forEach ((value) {
87
+ replyTweetKeyList.add (value);
88
+ });
89
+ });
90
+ commentCount = replyTweetKeyList.length;
91
+ } else {
92
+ replyTweetKeyList = [];
93
+ commentCount = 0 ;
68
94
}
69
- key = map['key' ];
70
- description = map['description' ];
71
- userId = map['userId' ];
72
- // name = map['name'];
73
- // profilePic = map['profilePic'];
74
- likeCount = map['likeCount' ];
75
- commentCount = map['commentCount' ];
76
- retweetCount = map["retweetCount" ] ?? 0 ;
77
- imagePath = map['imagePath' ];
78
- createdAt = map['createdAt' ];
79
- imagePath = map['imagePath' ];
80
- // username = map['username'];
81
- user = User .fromJson (map['user' ]);
82
- parentkey = map['parentkey' ];
83
- childRetwetkey = map['childRetwetkey' ];
84
- if (map['tags' ] != null ){
85
- tags = List <String >();
86
- map['tags' ].forEach ((value){
87
- tags.add (value);
88
- });
89
- }
90
- if (map['likeList' ] != null ){
91
- map['likeList' ].forEach ((key,value){
92
- if (value.containsKey ('userId' )){
93
- LikeList list = LikeList (key: key,userId: value['userId' ]);
94
- likeList.add (list);
95
- }
96
- });
97
- likeCount = likeList.length;
98
- }
99
- else {
100
- likeList = [];
101
- likeCount = 0 ;
102
- }
103
- if (map['replyTweetKeyList' ] != null ){
104
- map['replyTweetKeyList' ].forEach ((value){
105
- replyTweetKeyList = List <String >();
106
- map['replyTweetKeyList' ].forEach ((value){
107
- replyTweetKeyList.add (value);
108
- });
109
- });
110
- commentCount = replyTweetKeyList.length;
111
- }
112
- else {
113
- replyTweetKeyList = [];
114
- commentCount = 0 ;
115
- }
116
95
}
117
96
118
- bool get isValidTweet {
119
- bool isValid = false ;
120
- if (description != null
121
- && description.isNotEmpty
122
- && this .user != null
123
- && this .user.userName != null
124
- && this .user.userName.isNotEmpty
125
- ){
126
- isValid = true ;
127
- }
128
- else {
129
- print ("Invalid Tweet found. Id:- $key " );
130
- }
131
- return isValid;
132
- }
133
- }
134
- class LikeList {
135
- String key;
136
- String userId;
137
- LikeList ({this .key,this .userId});
138
- LikeList .fromJson (Map <dynamic , dynamic > map,{String key}) {
139
- key = key;
140
- userId = map['userId' ];
141
- }
142
- toJson (){
143
- return {
144
- 'userId' : userId
145
- };
97
+ bool get isValidTweet {
98
+ bool isValid = false ;
99
+ if (description != null &&
100
+ description.isNotEmpty &&
101
+ this .user != null &&
102
+ this .user.userName != null &&
103
+ this .user.userName.isNotEmpty) {
104
+ isValid = true ;
105
+ } else {
106
+ print ("Invalid Tweet found. Id:- $key " );
107
+ }
108
+ return isValid;
146
109
}
147
110
}
0 commit comments