1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_twitter_clone/helper/constant.dart' ;
3
+ import 'package:flutter_twitter_clone/helper/customRoute.dart' ;
3
4
import 'package:flutter_twitter_clone/helper/enum.dart' ;
4
5
import 'package:flutter_twitter_clone/helper/theme.dart' ;
5
6
import 'package:flutter_twitter_clone/helper/utility.dart' ;
6
7
import 'package:flutter_twitter_clone/model/feedModel.dart' ;
8
+ import 'package:flutter_twitter_clone/page/common/usersListPage.dart' ;
9
+ import 'package:flutter_twitter_clone/page/common/widget/userListWidget.dart' ;
10
+ import 'package:flutter_twitter_clone/page/message/chatScreenPage.dart' ;
7
11
import 'package:flutter_twitter_clone/state/authState.dart' ;
8
12
import 'package:flutter_twitter_clone/state/feedState.dart' ;
9
13
import 'package:flutter_twitter_clone/widgets/customWidgets.dart' ;
@@ -17,152 +21,235 @@ class TweetIconsRow extends StatelessWidget {
17
21
final double size;
18
22
final bool isTweetDetail;
19
23
final TweetType type;
20
- const TweetIconsRow ({Key key, this .model, this .iconColor, this .iconEnableColor, this .size, this .isTweetDetail = false , this .type}) : super (key: key);
24
+ const TweetIconsRow (
25
+ {Key key,
26
+ this .model,
27
+ this .iconColor,
28
+ this .iconEnableColor,
29
+ this .size,
30
+ this .isTweetDetail = false ,
31
+ this .type})
32
+ : super (key: key);
21
33
22
34
Widget _likeCommentsIcons (BuildContext context, FeedModel model) {
23
- var state = Provider .of <AuthState >(context,);
24
- return Container (
25
- color: Colors .transparent,
26
- padding: EdgeInsets .only (bottom: 0 ,top: 0 ),
27
- child: Row (
28
- mainAxisAlignment: MainAxisAlignment .start,
29
- children: < Widget > [
30
- SizedBox (width: 20 ,),
31
- _iconWidget (
32
- context,
33
- text: isTweetDetail ? '' : model.commentCount.toString (),
34
- icon: AppIcon .reply,iconColor: iconColor,
35
- size : size ?? 20 ,
36
- onPressed: (){
37
- var state = Provider .of <FeedState >(context,);
38
- state.setTweetToReply = model;
39
- Navigator .of (context).pushNamed ('/ComposeTweetPage' );
40
- },),
41
- _iconWidget (
42
- context,
43
- text: isTweetDetail ? '' : model.retweetCount.toString (),
44
- icon: AppIcon .retweet,iconColor: iconColor,size : size ?? 20 ,
45
- onPressed: (){
46
- TweetBottomSheet ().openRetweetbottomSheet (context, type, model);
47
- }
48
- ),
49
- _iconWidget (
50
- context,
51
- text: isTweetDetail ? '' : model.likeCount.toString (),
52
- icon: model.likeList.any ((x)=> x.userId == state.userId)
53
- ? AppIcon .heartFill
54
- : AppIcon .heartEmpty,
55
- onPressed: (){addLikeToTweet (context);},
56
- iconColor: model.likeList.any ((x)=> x.userId == state.userId )? iconEnableColor : iconColor ,
57
- size : size ?? 20
58
- ),
59
- _iconWidget (
60
- context,
61
- text: '' ,
62
- icon: null ,
63
- sysIcon: Icons .share,
64
- onPressed: (){share ('${model .description }' ,
65
- subject: '${model .user .displayName }\' s post' );},
66
- iconColor: iconColor,
67
- size : size ?? 20 ),
68
-
69
- ],
70
- )
35
+ var state = Provider .of <AuthState >(
36
+ context,
71
37
);
72
- }
73
- Widget _iconWidget (BuildContext context,{String text, int icon,Function onPressed,IconData sysIcon,Color iconColor, double size = 20 }){
74
- return Expanded (
75
- child: Container (
38
+ return Container (
39
+ color: Colors .transparent,
40
+ padding: EdgeInsets .only (bottom: 0 , top: 0 ),
76
41
child: Row (
42
+ mainAxisAlignment: MainAxisAlignment .start,
77
43
children: < Widget > [
78
- IconButton (
79
- onPressed: (){ if (onPressed != null )onPressed ();},
80
- icon: sysIcon != null ? Icon ( sysIcon,color: iconColor,size: size)
81
- : customIcon (context,size: size, icon: icon, istwitterIcon: true , iconColor: iconColor),
44
+ SizedBox (
45
+ width: 20 ,
82
46
),
83
- customText (text,style: TextStyle (fontWeight: FontWeight .bold, color: iconColor, fontSize: size - 5 ,),context: context),
47
+ _iconWidget (
48
+ context,
49
+ text: isTweetDetail ? '' : model.commentCount.toString (),
50
+ icon: AppIcon .reply,
51
+ iconColor: iconColor,
52
+ size: size ?? 20 ,
53
+ onPressed: () {
54
+ var state = Provider .of <FeedState >(
55
+ context,
56
+ );
57
+ state.setTweetToReply = model;
58
+ Navigator .of (context).pushNamed ('/ComposeTweetPage' );
59
+ },
60
+ ),
61
+ _iconWidget (context,
62
+ text: isTweetDetail ? '' : model.retweetCount.toString (),
63
+ icon: AppIcon .retweet,
64
+ iconColor: iconColor,
65
+ size: size ?? 20 , onPressed: () {
66
+ TweetBottomSheet ().openRetweetbottomSheet (context, type, model);
67
+ }),
68
+ _iconWidget (context,
69
+ text: isTweetDetail ? '' : model.likeCount.toString (),
70
+ icon: model.likeList.any ((x) => x.userId == state.userId)
71
+ ? AppIcon .heartFill
72
+ : AppIcon .heartEmpty, onPressed: () {
73
+ addLikeToTweet (context);
74
+ },
75
+ iconColor: model.likeList.any ((x) => x.userId == state.userId)
76
+ ? iconEnableColor
77
+ : iconColor,
78
+ size: size ?? 20 ),
79
+ _iconWidget (context, text: '' , icon: null , sysIcon: Icons .share,
80
+ onPressed: () {
81
+ share ('${model .description }' ,
82
+ subject: '${model .user .displayName }\' s post' );
83
+ }, iconColor: iconColor, size: size ?? 20 ),
84
84
],
85
- )
86
- )
87
- );
88
- }
89
- Widget _timeWidget (BuildContext context){
90
- return Column (children: < Widget > [
91
- SizedBox (height: 8 ,),
92
- Row (
93
- children: < Widget > [
94
- SizedBox (width: 5 ,),
95
- customText (getPostTime2 (model.createdAt),
96
- style: textStyle14),
97
- SizedBox (
98
- width: 10 ,
99
- ),
100
- customText ('Fwitter for Android' ,
101
- style: TextStyle (color: Theme .of (context).primaryColor))
102
- ],
103
- ),
104
- SizedBox (height: 5 ,),
105
- ],);
85
+ ));
106
86
}
107
- Widget _likeCommentWidget (){
108
- return Column (children: < Widget > [
109
- Padding (
110
- padding: EdgeInsets .only (right: 10 ),
111
- child: Divider (),
87
+
88
+ Widget _iconWidget (BuildContext context,
89
+ {String text,
90
+ int icon,
91
+ Function onPressed,
92
+ IconData sysIcon,
93
+ Color iconColor,
94
+ double size = 20 }) {
95
+ return Expanded (
96
+ child: Container (
97
+ child: Row (
98
+ children: < Widget > [
99
+ IconButton (
100
+ onPressed: () {
101
+ if (onPressed != null ) onPressed ();
102
+ },
103
+ icon: sysIcon != null
104
+ ? Icon (sysIcon, color: iconColor, size: size)
105
+ : customIcon (context,
106
+ size: size,
107
+ icon: icon,
108
+ istwitterIcon: true ,
109
+ iconColor: iconColor),
112
110
),
111
+ customText (text,
112
+ style: TextStyle (
113
+ fontWeight: FontWeight .bold,
114
+ color: iconColor,
115
+ fontSize: size - 5 ,
116
+ ),
117
+ context: context),
118
+ ],
119
+ )));
120
+ }
121
+
122
+ Widget _timeWidget (BuildContext context) {
123
+ return Column (
124
+ children: < Widget > [
113
125
SizedBox (
114
- height: 5 ,
126
+ height: 8 ,
115
127
),
116
128
Row (
117
- mainAxisAlignment: MainAxisAlignment .start,
118
129
children: < Widget > [
119
- SizedBox (
120
- width: 10 ,
121
- ),
122
- customText (model.retweetCount.toString (),
123
- style: TextStyle (fontWeight: FontWeight .bold)),
124
130
SizedBox (
125
131
width: 5 ,
126
132
),
127
- customText ('Retweets' , style: subtitleStyle),
128
- SizedBox (
129
- width: 20 ,
130
- ),
131
- customSwitcherWidget (
132
- duraton: Duration (milliseconds: 300 ),
133
- child: customText (model.likeCount.toString (),
134
- style: TextStyle (fontWeight: FontWeight .bold),
135
- key: ValueKey (model.likeCount)),
136
- ),
133
+ customText (getPostTime2 (model.createdAt), style: textStyle14),
137
134
SizedBox (
138
- width: 5 ,
135
+ width: 10 ,
139
136
),
140
- customText ('Likes' , style: subtitleStyle)
137
+ customText ('Fwitter for Android' ,
138
+ style: TextStyle (color: Theme .of (context).primaryColor))
141
139
],
142
140
),
143
141
SizedBox (
144
- height: 10 ,
142
+ height: 5 ,
143
+ ),
144
+ ],
145
+ );
146
+ }
147
+
148
+ Widget _likeCommentWidget (BuildContext context) {
149
+ bool isLikeAvailable = model.likeCount > 0 ;
150
+ bool isRetweetAvailable = model.retweetCount > 0 ;
151
+ bool isLikeRetweetAvailable = isRetweetAvailable || isLikeAvailable;
152
+ return Column (
153
+ children: < Widget > [
154
+ Divider (
155
+ endIndent: 10 ,
156
+ height: 0 ,
145
157
),
146
- Padding (
147
- padding: EdgeInsets .only (right: 10 ),
148
- child: Divider (),
158
+ AnimatedContainer (
159
+ padding:
160
+ EdgeInsets .symmetric (vertical: isLikeRetweetAvailable ? 12 : 0 ),
161
+ duration: Duration (milliseconds: 500 ),
162
+ child: ! isLikeRetweetAvailable
163
+ ? SizedBox .shrink ()
164
+ : Row (
165
+ crossAxisAlignment: CrossAxisAlignment .center,
166
+ mainAxisAlignment: MainAxisAlignment .start,
167
+ children: < Widget > [
168
+ ! isRetweetAvailable
169
+ ? SizedBox .shrink ()
170
+ : customText (model.retweetCount.toString (),
171
+ style: TextStyle (fontWeight: FontWeight .bold)),
172
+ ! isRetweetAvailable
173
+ ? SizedBox .shrink ()
174
+ : SizedBox (width: 5 ),
175
+ AnimatedCrossFade (
176
+ firstChild: SizedBox .shrink (),
177
+ secondChild: customText ('Retweets' , style: subtitleStyle),
178
+ crossFadeState: ! isRetweetAvailable
179
+ ? CrossFadeState .showFirst
180
+ : CrossFadeState .showSecond,
181
+ duration: Duration (milliseconds: 800 ),
182
+ ),
183
+ ! isRetweetAvailable
184
+ ? SizedBox .shrink ()
185
+ : SizedBox (width: 20 ),
186
+ InkWell (
187
+ onTap: () {
188
+ onLikeTextPressed (context);
189
+ },
190
+ child: AnimatedCrossFade (
191
+ firstChild: SizedBox .shrink (),
192
+ secondChild: Row (
193
+ children: < Widget > [
194
+ customSwitcherWidget (
195
+ duraton: Duration (milliseconds: 300 ),
196
+ child: customText (model.likeCount.toString (),
197
+ style: TextStyle (fontWeight: FontWeight .bold),
198
+ key: ValueKey (model.likeCount)),
199
+ ),
200
+ SizedBox (width: 5 ),
201
+ customText ('Likes' , style: subtitleStyle)
202
+ ],
203
+ ),
204
+ crossFadeState: ! isLikeAvailable
205
+ ? CrossFadeState .showFirst
206
+ : CrossFadeState .showSecond,
207
+ duration: Duration (milliseconds: 300 ),
208
+ ),
209
+ )
210
+ ],
211
+ ),
149
212
),
150
- ],);
213
+ ! isLikeRetweetAvailable
214
+ ? SizedBox .shrink ()
215
+ : Divider (
216
+ endIndent: 10 ,
217
+ height: 0 ,
218
+ ),
219
+ ],
220
+ );
151
221
}
222
+
152
223
void addLikeToTweet (BuildContext context) {
153
- var state = Provider .of <FeedState >(context,);
154
- var authState = Provider .of <AuthState >(context,);
224
+ var state = Provider .of <FeedState >(
225
+ context,
226
+ );
227
+ var authState = Provider .of <AuthState >(
228
+ context,
229
+ );
155
230
state.addLikeToTweet (model, authState.userId);
156
231
}
232
+
233
+ void onLikeTextPressed (BuildContext context) {
234
+ Navigator .of (context).push (
235
+ CustomRoute <bool >(
236
+ builder: (BuildContext context) => UsersListPage (
237
+ pageTitle: "Liked by" ,
238
+ userList: model.likeList.map ((x) => x.userId).toList (),
239
+ ),
240
+ ),
241
+ );
242
+ }
243
+
157
244
@override
158
245
Widget build (BuildContext context) {
159
246
return Container (
160
- child: Column (children : < Widget > [
161
- isTweetDetail ? _timeWidget (context) : SizedBox (),
162
- isTweetDetail ? _likeCommentWidget ( ) : SizedBox (),
163
-
164
- _likeCommentsIcons (context, model)
165
- ],)
166
- );
247
+ child: Column (
248
+ children : < Widget > [
249
+ isTweetDetail ? _timeWidget (context ) : SizedBox (),
250
+ isTweetDetail ? _likeCommentWidget (context) : SizedBox (),
251
+ _likeCommentsIcons (context, model)
252
+ ],
253
+ )) ;
167
254
}
168
- }
255
+ }
0 commit comments