Skip to content

Commit c840552

Browse files
committed
✨ Add Tweet like list
1. Users list added who liked tweet.
1 parent 84985bd commit c840552

File tree

2 files changed

+216
-121
lines changed

2 files changed

+216
-121
lines changed

lib/helper/routes.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,23 @@ class Routes{
6161
isTweet = true;
6262
}
6363
return CustomRoute<bool>(builder:(BuildContext context)=> ComposeTweetPage(isRetweet:isRetweet, isTweet: isTweet));
64-
case "FeedPostDetail":var postId = pathElements[2];
65-
return SlideLeftRoute<bool>(builder:(BuildContext context)=> FeedPostDetail(postId: postId,),settings: RouteSettings(name:'FeedPostDetail'));
64+
case "FeedPostDetail":
65+
var postId = pathElements[2];
66+
return SlideLeftRoute<bool>(builder:(BuildContext context)=> FeedPostDetail(postId: postId,),settings: RouteSettings(name:'FeedPostDetail'));
67+
case "ProfilePage":
68+
String profileId;
69+
if(pathElements.length > 2){
70+
profileId = pathElements[2];
71+
}
72+
return CustomRoute<bool>(builder:(BuildContext context)=> ProfilePage(
73+
profileId: profileId,
74+
));
6675
case "WelcomePage":return CustomRoute<bool>(builder:(BuildContext context)=> WelcomePage());
6776
case "SignIn":return CustomRoute<bool>(builder:(BuildContext context)=> SignIn());
6877
case "SignUp":return CustomRoute<bool>(builder:(BuildContext context)=> Signup());
6978
case "ForgetPasswordPage":return CustomRoute<bool>(builder:(BuildContext context)=> ForgetPasswordPage());
7079
case "CreateFeedPage":return CustomRoute<bool>(builder:(BuildContext context)=> CreateFeedPage(),);
7180
case "SearchPage":return CustomRoute<bool>(builder:(BuildContext context)=> SearchPage());
72-
case "ProfilePage":return CustomRoute<bool>(builder:(BuildContext context)=> ProfilePage());
7381
case "ImageViewPge":return CustomRoute<bool>(builder:(BuildContext context)=> ImageViewPge());
7482
case "EditProfile":return CustomRoute<bool>(builder:(BuildContext context)=> EditProfilePage());
7583
case "ChatScreenPage":return CustomRoute<bool>(builder:(BuildContext context)=> ChatScreenPage());
Lines changed: 205 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_twitter_clone/helper/constant.dart';
3+
import 'package:flutter_twitter_clone/helper/customRoute.dart';
34
import 'package:flutter_twitter_clone/helper/enum.dart';
45
import 'package:flutter_twitter_clone/helper/theme.dart';
56
import 'package:flutter_twitter_clone/helper/utility.dart';
67
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';
711
import 'package:flutter_twitter_clone/state/authState.dart';
812
import 'package:flutter_twitter_clone/state/feedState.dart';
913
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
@@ -17,152 +21,235 @@ class TweetIconsRow extends StatelessWidget {
1721
final double size;
1822
final bool isTweetDetail;
1923
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);
2133

2234
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,
7137
);
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),
7641
child: Row(
42+
mainAxisAlignment: MainAxisAlignment.start,
7743
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,
8246
),
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),
8484
],
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+
));
10686
}
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),
112110
),
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>[
113125
SizedBox(
114-
height: 5,
126+
height: 8,
115127
),
116128
Row(
117-
mainAxisAlignment: MainAxisAlignment.start,
118129
children: <Widget>[
119-
SizedBox(
120-
width: 10,
121-
),
122-
customText(model.retweetCount.toString(),
123-
style: TextStyle(fontWeight: FontWeight.bold)),
124130
SizedBox(
125131
width: 5,
126132
),
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),
137134
SizedBox(
138-
width: 5,
135+
width: 10,
139136
),
140-
customText('Likes', style: subtitleStyle)
137+
customText('Fwitter for Android',
138+
style: TextStyle(color: Theme.of(context).primaryColor))
141139
],
142140
),
143141
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,
145157
),
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+
),
149212
),
150-
],);
213+
!isLikeRetweetAvailable
214+
? SizedBox.shrink()
215+
: Divider(
216+
endIndent: 10,
217+
height: 0,
218+
),
219+
],
220+
);
151221
}
222+
152223
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+
);
155230
state.addLikeToTweet(model, authState.userId);
156231
}
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+
157244
@override
158245
Widget build(BuildContext context) {
159246
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+
));
167254
}
168-
}
255+
}

0 commit comments

Comments
 (0)