@@ -13,19 +13,98 @@ import 'package:provider/provider.dart';
13
13
14
14
class UserListWidget extends StatelessWidget {
15
15
final List <String > list;
16
- final fetchingListbool;
17
16
final String emptyScreenText;
18
17
final String emptyScreenSubTileText;
19
- String myId;
20
18
UserListWidget (
21
19
{Key key,
22
20
this .list,
23
21
this .emptyScreenText,
24
- this .fetchingListbool,
25
22
this .emptyScreenSubTileText})
26
23
: super (key: key);
27
- Widget _userTile (BuildContext context, User user) {
28
- bool isFollow = isFollowing (user);
24
+
25
+ @override
26
+ Widget build (BuildContext context) {
27
+ var state = Provider .of <AuthState >(context, listen: false );
28
+ String myId = state.userModel.key;
29
+ return list != null && list.isNotEmpty
30
+ ? ListView .separated (
31
+ itemBuilder: (context, index) {
32
+ return FutureBuilder (
33
+ future: state.getuserDetail (list[index]),
34
+ builder: (context, AsyncSnapshot <User > snapshot) {
35
+ if (snapshot.hasData) {
36
+ return UserTile (
37
+ user: snapshot.data,
38
+ myId: myId,
39
+ );
40
+ } else if (index == 0 ) {
41
+ return Container (
42
+ child: SizedBox (
43
+ height: 3 ,
44
+ child: LinearProgressIndicator (),
45
+ ));
46
+ } else {
47
+ return SizedBox .shrink ();
48
+ }
49
+ },
50
+ );
51
+ },
52
+ separatorBuilder: (context, index) {
53
+ return Divider (
54
+ height: 0 ,
55
+ );
56
+ },
57
+ itemCount: list.length,
58
+ )
59
+ : state.isbusy
60
+ ? SizedBox (
61
+ height: 3 ,
62
+ child: LinearProgressIndicator (),
63
+ )
64
+ : Container (
65
+ width: fullWidth (context),
66
+ padding: EdgeInsets .only (top: 0 , left: 30 , right: 30 ),
67
+ child: NotifyText (
68
+ title: emptyScreenText,
69
+ subTitle: emptyScreenSubTileText,
70
+ ),
71
+ );
72
+ }
73
+ }
74
+
75
+ class UserTile extends StatelessWidget {
76
+ const UserTile ({Key key, this .user, this .myId}) : super (key: key);
77
+ final User user;
78
+ final String myId;
79
+
80
+ /// Return empty string for default bio
81
+ /// Max length of bio is 100
82
+ String getBio (String bio) {
83
+ if (bio != null && bio.isNotEmpty && bio != "Edit profile to update bio" ) {
84
+ if (bio.length > 100 ) {
85
+ bio = bio.substring (0 , 100 ) + '...' ;
86
+ return bio;
87
+ } else {
88
+ return bio;
89
+ }
90
+ }
91
+ return null ;
92
+ }
93
+
94
+ /// Check if user followerlist contain your or not
95
+ /// If your id exist in follower list it mean you are following him
96
+ bool isFollowing () {
97
+ if (user.followersList != null &&
98
+ user.followersList.any ((x) => x == myId)) {
99
+ return true ;
100
+ } else {
101
+ return false ;
102
+ }
103
+ }
104
+
105
+ @override
106
+ Widget build (BuildContext context) {
107
+ bool isFollow = isFollowing ();
29
108
return Container (
30
109
padding: EdgeInsets .symmetric (vertical: 10 ),
31
110
color: TwitterColor .white,
@@ -103,71 +182,4 @@ class UserListWidget extends StatelessWidget {
103
182
),
104
183
);
105
184
}
106
-
107
- String getBio (String bio) {
108
- if (bio != null && bio.isNotEmpty && bio != "Edit profile to update bio" ) {
109
- if (bio.length > 100 ) {
110
- bio = bio.substring (0 , 100 ) + '...' ;
111
- return bio;
112
- } else {
113
- return bio;
114
- }
115
- }
116
- return null ;
117
- }
118
-
119
- bool isFollowing (User model) {
120
- if (model.followersList != null &&
121
- model.followersList.any ((x) => x == myId)) {
122
- return true ;
123
- } else {
124
- return false ;
125
- }
126
- }
127
-
128
- @override
129
- Widget build (BuildContext context) {
130
- var state = Provider .of <AuthState >(context, listen: false );
131
- myId = state.userModel.key;
132
- return list != null && list.isNotEmpty
133
- ? ListView .separated (
134
- itemBuilder: (context, index) {
135
- return FutureBuilder (
136
- future: state.getuserDetail (list[index]),
137
- builder: (context, AsyncSnapshot <User > snapshot) {
138
- if (snapshot.hasData) {
139
- return _userTile (context, snapshot.data);
140
- } else if (index == 0 ) {
141
- return Container (
142
- child: SizedBox (
143
- height: 3 ,
144
- child: LinearProgressIndicator (),
145
- ));
146
- } else {
147
- return SizedBox .shrink ();
148
- }
149
- },
150
- );
151
- },
152
- separatorBuilder: (context, index) {
153
- return Divider (
154
- height: 0 ,
155
- );
156
- },
157
- itemCount: list.length,
158
- )
159
- : fetchingListbool
160
- ? SizedBox (
161
- height: 3 ,
162
- child: LinearProgressIndicator (),
163
- )
164
- : Container (
165
- width: fullWidth (context),
166
- padding: EdgeInsets .only (top: 0 , left: 30 , right: 30 ),
167
- child: NotifyText (
168
- title: emptyScreenText,
169
- subTitle: emptyScreenSubTileText,
170
- ),
171
- );
172
- }
173
185
}
0 commit comments