@@ -12,11 +12,13 @@ import 'package:flutter_twitter_clone/widgets/customAppBar.dart';
12
12
import 'package:flutter_twitter_clone/widgets/customWidgets.dart' ;
13
13
import 'package:flutter_twitter_clone/widgets/newWidget/customUrlText.dart' ;
14
14
import 'package:flutter_twitter_clone/widgets/newWidget/emptyList.dart' ;
15
+ import 'package:flutter_twitter_clone/widgets/newWidget/title_text.dart' ;
15
16
import 'package:provider/provider.dart' ;
16
17
17
18
class NotificationPage extends StatefulWidget {
18
19
NotificationPage ({Key key, this .scaffoldKey}) : super (key: key);
19
20
21
+ /// scaffoldKey used to open sidebaar drawer
20
22
final GlobalKey <ScaffoldState > scaffoldKey;
21
23
22
24
_NotificationPageState createState () => _NotificationPageState ();
@@ -33,69 +35,38 @@ class _NotificationPageState extends State<NotificationPage> {
33
35
});
34
36
}
35
37
36
- Widget _body () {
37
- var state = Provider .of <NotificationState >(context);
38
- var list = state.notificationList;
39
- if (state? .isbusy ?? true && (list == null || list.isEmpty)) {
40
- return SizedBox (
41
- height: 3 ,
42
- child: LinearProgressIndicator (),
43
- );
44
- } else if (list == null || list.isEmpty) {
45
- return Padding (
46
- padding: EdgeInsets .symmetric (horizontal: 30 ),
47
- child: EmptyList (
48
- 'No Notification available yet' ,
49
- subTitle: 'When new notificaion found, they\' ll show up here.' ,
38
+ void onSettingIconPressed () {
39
+ Navigator .pushNamed (context, '/NotificationPage' );
40
+ }
41
+
42
+ @override
43
+ Widget build (BuildContext context) {
44
+ return Scaffold (
45
+ backgroundColor: TwitterColor .mystic,
46
+ appBar: CustomAppBar (
47
+ scaffoldKey: widget.scaffoldKey,
48
+ title: customTitleText (
49
+ 'Notifications' ,
50
50
),
51
- );
52
- }
53
- return ListView .separated (
54
- physics: BouncingScrollPhysics (),
55
- addAutomaticKeepAlives: true ,
56
- itemBuilder: (context, index) => _notificationRow (list[index]),
57
- separatorBuilder: (context, index) => Divider (
58
- height: 0 ,
51
+ icon: AppIcon .settings,
52
+ onActionPressed: onSettingIconPressed,
59
53
),
60
- itemCount : list.length ,
54
+ body : NotificationPageBody () ,
61
55
);
62
56
}
57
+ }
63
58
64
- void onSettingIconPressed () {
65
- Navigator .pushNamed (context, '/NotificationPage' );
66
- }
59
+ class NotificationPageBody extends StatelessWidget {
60
+ const NotificationPageBody ({Key key}) : super (key: key);
67
61
68
- Widget _notificationRow (NotificationModel model) {
62
+ Widget _notificationRow (BuildContext context, NotificationModel model) {
69
63
var state = Provider .of <NotificationState >(context);
70
64
return FutureBuilder (
71
65
future: state.getTweetDetail (model.tweetKey),
72
66
builder: (BuildContext context, AsyncSnapshot <FeedModel > snapshot) {
73
67
if (snapshot.hasData) {
74
- var des = snapshot.data.description.length > 150
75
- ? snapshot.data.description.substring (0 , 150 ) + '...'
76
- : snapshot.data.description;
77
- return Container (
78
- padding: EdgeInsets .symmetric (vertical: 10 ),
79
- color: TwitterColor .white,
80
- child: ListTile (
81
- onTap: () {
82
- var state = Provider .of <FeedState >(context);
83
- state.getpostDetailFromDatabase (null , model: snapshot.data);
84
- Navigator .of (context)
85
- .pushNamed ('/FeedPostDetail/' + model.tweetKey);
86
- },
87
- title: _userList (snapshot.data.likeList),
88
- subtitle: Padding (
89
- padding: EdgeInsets .only (left: 60 ),
90
- child: UrlText (
91
- text: des,
92
- style: TextStyle (
93
- color: AppColor .darkGrey,
94
- fontWeight: FontWeight .w400,
95
- ),
96
- ),
97
- ),
98
- ),
68
+ return NotificationTile (
69
+ model: snapshot.data,
99
70
);
100
71
} else if (snapshot.connectionState == ConnectionState .waiting ||
101
72
snapshot.connectionState == ConnectionState .active) {
@@ -104,19 +75,68 @@ class _NotificationPageState extends State<NotificationPage> {
104
75
child: LinearProgressIndicator (),
105
76
);
106
77
} else {
78
+ /// remove notification from firebase db if tweet in not available or deleted.
79
+ var authstate = Provider .of <AuthState >(context);
80
+ state.removeNotification (authstate.userId, model.tweetKey);
107
81
return SizedBox ();
108
82
}
109
83
},
110
84
);
111
85
}
112
86
113
- Widget _userList (List <LikeList > list) {
87
+ @override
88
+ Widget build (BuildContext context) {
89
+ var state = Provider .of <NotificationState >(context);
90
+ var list = state.notificationList;
91
+ if (state? .isbusy ?? true && (list == null || list.isEmpty)) {
92
+ return SizedBox (
93
+ height: 3 ,
94
+ child: LinearProgressIndicator (),
95
+ );
96
+ } else if (list == null || list.isEmpty) {
97
+ return Padding (
98
+ padding: EdgeInsets .symmetric (horizontal: 30 ),
99
+ child: EmptyList (
100
+ 'No Notification available yet' ,
101
+ subTitle: 'When new notificaion found, they\' ll show up here.' ,
102
+ ),
103
+ );
104
+ }
105
+ return ListView .builder (
106
+ physics: BouncingScrollPhysics (),
107
+ addAutomaticKeepAlives: true ,
108
+ itemBuilder: (context, index) => _notificationRow (context, list[index]),
109
+ itemCount: list.length,
110
+ );
111
+ }
112
+ }
113
+
114
+ class NotificationTile extends StatelessWidget {
115
+ final FeedModel model;
116
+ const NotificationTile ({Key key, this .model}) : super (key: key);
117
+ Widget _userList (BuildContext context, List <LikeList > list) {
118
+ // List<String> names = [];
114
119
var length = list.length;
120
+ List <Widget > avaterList = [];
121
+ final int noOfUser = list.length;
122
+ var state = Provider .of <NotificationState >(context);
115
123
if (list != null && list.length > 5 ) {
116
124
list = list.take (5 ).toList ();
117
125
}
118
- List <String > name = [];
119
- var state = Provider .of <NotificationState >(context);
126
+ avaterList = list.map ((x) {
127
+ return _userAvater (x.userId, state, (name) {
128
+ // names.add(name);
129
+ });
130
+ }).toList ();
131
+ if (noOfUser > 5 ) {
132
+ avaterList.add (
133
+ Text (
134
+ " +${noOfUser - 5 }" ,
135
+ style: subtitleStyle.copyWith (fontSize: 16 ),
136
+ ),
137
+ );
138
+ }
139
+
120
140
var col = Column (
121
141
crossAxisAlignment: CrossAxisAlignment .start,
122
142
children: < Widget > [
@@ -129,60 +149,80 @@ class _NotificationPageState extends State<NotificationPage> {
129
149
istwitterIcon: true ,
130
150
size: 25 ),
131
151
SizedBox (width: 10 ),
132
- Row (
133
- children: list.map ((x) {
134
- return FutureBuilder (
135
- future: state.getuserDetail (x.userId),
136
- // initialData: InitialData,
137
- builder:
138
- (BuildContext context, AsyncSnapshot <User > snapshot) {
139
- if (snapshot.hasData) {
140
- name.add (snapshot.data.displayName);
141
- return Padding (
142
- padding: EdgeInsets .symmetric (horizontal: 3 ),
143
- child: GestureDetector (
144
- onTap: () {
145
- Navigator .of (context).pushNamed (
146
- '/ProfilePage/' + snapshot.data? .userId);
147
- },
148
- child: customImage (context, snapshot.data.profilePic,
149
- height: 30 ),
150
- ),
151
- );
152
- } else {
153
- return Container ();
154
- }
155
- },
156
- );
157
- }).toList (),
158
- ),
152
+ Row (children: avaterList),
159
153
],
160
154
),
155
+ // names.length > 0 ? Text(names[0]) : SizedBox(),
161
156
Padding (
162
157
padding: EdgeInsets .only (left: 60 , bottom: 5 , top: 5 ),
163
- child: UrlText (
164
- text: '$length people like your Tweet' ,
165
- style: TextStyle (fontSize: 18 , color: Colors .black87),
158
+ child: TitleText (
159
+ '$length people like your Tweet' ,
160
+ fontSize: 18 ,
161
+ color: Colors .black87,
162
+ fontWeight: FontWeight .w500,
166
163
),
167
164
)
168
165
],
169
166
);
170
167
return col;
171
168
}
172
169
170
+ Widget _userAvater (
171
+ String userId, NotificationState state, ValueChanged <String > name) {
172
+ return FutureBuilder (
173
+ future: state.getuserDetail (userId),
174
+ // initialData: InitialData,
175
+ builder: (BuildContext context, AsyncSnapshot <User > snapshot) {
176
+ if (snapshot.hasData) {
177
+ name (snapshot.data.displayName);
178
+ return Padding (
179
+ padding: EdgeInsets .symmetric (horizontal: 3 ),
180
+ child: GestureDetector (
181
+ onTap: () {
182
+ Navigator .of (context)
183
+ .pushNamed ('/ProfilePage/' + snapshot.data? .userId);
184
+ },
185
+ child: customImage (context, snapshot.data.profilePic, height: 30 ),
186
+ ),
187
+ );
188
+ } else {
189
+ return Container ();
190
+ }
191
+ },
192
+ );
193
+ }
194
+
173
195
@override
174
196
Widget build (BuildContext context) {
175
- return Scaffold (
176
- backgroundColor: TwitterColor .mystic,
177
- appBar: CustomAppBar (
178
- scaffoldKey: widget.scaffoldKey,
179
- title: customTitleText (
180
- 'Notifications' ,
197
+ var description = model.description.length > 150
198
+ ? model.description.substring (0 , 150 ) + '...'
199
+ : model.description;
200
+ return Column (
201
+ children: < Widget > [
202
+ Container (
203
+ padding: EdgeInsets .symmetric (vertical: 10 ),
204
+ color: TwitterColor .white,
205
+ child: ListTile (
206
+ onTap: () {
207
+ var state = Provider .of <FeedState >(context);
208
+ state.getpostDetailFromDatabase (null , model: model);
209
+ Navigator .of (context).pushNamed ('/FeedPostDetail/' + model.key);
210
+ },
211
+ title: _userList (context, model.likeList),
212
+ subtitle: Padding (
213
+ padding: EdgeInsets .only (left: 60 ),
214
+ child: UrlText (
215
+ text: description,
216
+ style: TextStyle (
217
+ color: AppColor .darkGrey,
218
+ fontWeight: FontWeight .w400,
219
+ ),
220
+ ),
221
+ ),
222
+ ),
181
223
),
182
- icon: AppIcon .settings,
183
- onActionPressed: onSettingIconPressed,
184
- ),
185
- body: _body (),
224
+ Divider (height: 0 , thickness: .6 )
225
+ ],
186
226
);
187
227
}
188
228
}
0 commit comments