1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_twitter_clone/helper/constant.dart' ;
3
3
import 'package:flutter_twitter_clone/helper/enum.dart' ;
4
+ import 'package:flutter_twitter_clone/helper/theme.dart' ;
4
5
import 'package:flutter_twitter_clone/helper/utility.dart' ;
5
6
import 'package:flutter_twitter_clone/model/feedModel.dart' ;
6
7
import 'package:flutter_twitter_clone/state/authState.dart' ;
7
8
import 'package:flutter_twitter_clone/state/feedState.dart' ;
8
9
import 'package:flutter_twitter_clone/widgets/customWidgets.dart' ;
9
10
import 'package:provider/provider.dart' ;
10
11
11
- class TweetIconsRow extends StatefulWidget {
12
+ class TweetIconsRow extends StatelessWidget {
12
13
final FeedModel model;
13
14
final Color iconColor;
14
15
final Color iconEnableColor;
@@ -17,14 +18,8 @@ class TweetIconsRow extends StatefulWidget {
17
18
final TweetType type;
18
19
const TweetIconsRow ({Key key, this .model, this .iconColor, this .iconEnableColor, this .size, this .isTweetDetail = false , this .type}) : super (key: key);
19
20
20
- _TweetIconsRowState createState () => _TweetIconsRowState ();
21
- }
22
-
23
- class _TweetIconsRowState extends State <TweetIconsRow > {
24
-
25
- Widget _likeCommentsIcons (FeedModel model) {
21
+ Widget _likeCommentsIcons (BuildContext context, FeedModel model) {
26
22
var state = Provider .of <AuthState >(context,);
27
- var feedstate = Provider .of <FeedState >(context,);
28
23
return Container (
29
24
color: Colors .transparent,
30
25
padding: EdgeInsets .only (bottom: 0 ,top: 0 ),
@@ -33,38 +28,42 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
33
28
children: < Widget > [
34
29
SizedBox (width: 20 ,),
35
30
_iconWidget (
36
- text: widget.isTweetDetail ? '' : model.commentCount.toString (),
37
- icon: AppIcon .reply,iconColor: widget.iconColor,
38
- size : widget.size ?? 20 ,
31
+ context,
32
+ text: isTweetDetail ? '' : model.commentCount.toString (),
33
+ icon: AppIcon .reply,iconColor: iconColor,
34
+ size : size ?? 20 ,
39
35
onPressed: (){
40
36
Navigator .of (context).pushNamed ('/FeedPostReplyPage/' + model.key);
41
37
},),
42
38
_iconWidget (
43
- text: widget.isTweetDetail ? '' : model.commentCount.toString (),
44
- icon: AppIcon .retweet,iconColor: widget.iconColor,size : widget.size ?? 20 ),
39
+ context,
40
+ text: isTweetDetail ? '' : model.commentCount.toString (),
41
+ icon: AppIcon .retweet,iconColor: iconColor,size : size ?? 20 ),
45
42
_iconWidget (
46
- text: widget.isTweetDetail ? '' : model.likeCount.toString (),
43
+ context,
44
+ text: isTweetDetail ? '' : model.likeCount.toString (),
47
45
icon: model.likeList.any ((x)=> x.userId == state.userId)
48
46
? AppIcon .heartFill
49
47
: AppIcon .heartEmpty,
50
- onPressed: (){addLikeToTweet ();},
51
- iconColor: model.likeList.any ((x)=> x.userId == state.userId )? widget. iconEnableColor : widget. iconColor ,
52
- size : widget. size ?? 20
48
+ onPressed: (){addLikeToTweet (context );},
49
+ iconColor: model.likeList.any ((x)=> x.userId == state.userId )? iconEnableColor : iconColor ,
50
+ size : size ?? 20
53
51
),
54
52
_iconWidget (
53
+ context,
55
54
text: '' ,
56
55
icon: null ,
57
56
sysIcon: Icons .share,
58
57
onPressed: (){share ('${model .description }' ,
59
58
subject: '${model .user .displayName }\' s post' );},
60
- iconColor: widget. iconColor,
61
- size : widget. size ?? 20 ),
59
+ iconColor: iconColor,
60
+ size : size ?? 20 ),
62
61
63
62
],
64
63
)
65
64
);
66
65
}
67
- Widget _iconWidget ({String text, int icon,Function onPressed,IconData sysIcon,Color iconColor, double size = 20 }){
66
+ Widget _iconWidget (BuildContext context, {String text, int icon,Function onPressed,IconData sysIcon,Color iconColor, double size = 20 }){
68
67
return Expanded (
69
68
child: Container (
70
69
child: Row (
@@ -80,16 +79,17 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
80
79
)
81
80
);
82
81
}
83
- Widget _timeWidget (){
82
+ Widget _timeWidget (BuildContext context ){
84
83
return Column (children: < Widget > [
85
- SizedBox (height: 15 ,),
84
+ SizedBox (height: 5 ,),
86
85
Row (
87
86
children: < Widget > [
88
- customText (getPostTime2 (widget.model.createdAt),
87
+ SizedBox (width: 5 ,),
88
+ customText (getPostTime2 (model.createdAt),
89
89
style: TextStyle (
90
90
fontSize: 14 ,
91
91
fontWeight: FontWeight .w500,
92
- color: Colors .black54 )),
92
+ color: TwitterColor .woodsmoke_50 )),
93
93
SizedBox (
94
94
width: 10 ,
95
95
),
@@ -115,7 +115,7 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
115
115
SizedBox (
116
116
width: 10 ,
117
117
),
118
- customText (widget. model.commentCount.toString (),
118
+ customText (model.commentCount.toString (),
119
119
style: TextStyle (fontWeight: FontWeight .bold)),
120
120
SizedBox (
121
121
width: 10 ,
@@ -126,9 +126,9 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
126
126
),
127
127
customSwitcherWidget (
128
128
duraton: Duration (milliseconds: 300 ),
129
- child: customText (widget. model.likeCount.toString (),
129
+ child: customText (model.likeCount.toString (),
130
130
style: TextStyle (fontWeight: FontWeight .bold),
131
- key: ValueKey (widget. model.likeCount)),
131
+ key: ValueKey (model.likeCount)),
132
132
),
133
133
SizedBox (
134
134
width: 10 ,
@@ -145,19 +145,19 @@ class _TweetIconsRowState extends State<TweetIconsRow> {
145
145
),
146
146
],);
147
147
}
148
- void addLikeToTweet () {
148
+ void addLikeToTweet (BuildContext context ) {
149
149
var state = Provider .of <FeedState >(context,);
150
150
var authState = Provider .of <AuthState >(context,);
151
- state.addLikeToTweet (widget. model, authState.userId);
151
+ state.addLikeToTweet (model, authState.userId);
152
152
}
153
153
@override
154
154
Widget build (BuildContext context) {
155
155
return Container (
156
156
child: Column (children: < Widget > [
157
- widget. isTweetDetail ? _timeWidget () : SizedBox (),
158
- widget. isTweetDetail ? _likeCommentWidget () : SizedBox (),
157
+ isTweetDetail ? _timeWidget (context) : SizedBox (),
158
+ isTweetDetail ? _likeCommentWidget () : SizedBox (),
159
159
160
- _likeCommentsIcons (widget. model)
160
+ _likeCommentsIcons (context, model)
161
161
],)
162
162
);
163
163
}
0 commit comments