@@ -12,11 +12,13 @@ import 'package:flutter_twitter_clone/widgets/customAppBar.dart';
1212import 'package:flutter_twitter_clone/widgets/customWidgets.dart' ;
1313import 'package:flutter_twitter_clone/widgets/newWidget/customUrlText.dart' ;
1414import 'package:flutter_twitter_clone/widgets/newWidget/emptyList.dart' ;
15+ import 'package:flutter_twitter_clone/widgets/newWidget/title_text.dart' ;
1516import 'package:provider/provider.dart' ;
1617
1718class NotificationPage extends StatefulWidget {
1819 NotificationPage ({Key key, this .scaffoldKey}) : super (key: key);
1920
21+ /// scaffoldKey used to open sidebaar drawer
2022 final GlobalKey <ScaffoldState > scaffoldKey;
2123
2224 _NotificationPageState createState () => _NotificationPageState ();
@@ -33,69 +35,38 @@ class _NotificationPageState extends State<NotificationPage> {
3335 });
3436 }
3537
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' ,
5050 ),
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,
5953 ),
60- itemCount : list.length ,
54+ body : NotificationPageBody () ,
6155 );
6256 }
57+ }
6358
64- void onSettingIconPressed () {
65- Navigator .pushNamed (context, '/NotificationPage' );
66- }
59+ class NotificationPageBody extends StatelessWidget {
60+ const NotificationPageBody ({Key key}) : super (key: key);
6761
68- Widget _notificationRow (NotificationModel model) {
62+ Widget _notificationRow (BuildContext context, NotificationModel model) {
6963 var state = Provider .of <NotificationState >(context);
7064 return FutureBuilder (
7165 future: state.getTweetDetail (model.tweetKey),
7266 builder: (BuildContext context, AsyncSnapshot <FeedModel > snapshot) {
7367 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,
9970 );
10071 } else if (snapshot.connectionState == ConnectionState .waiting ||
10172 snapshot.connectionState == ConnectionState .active) {
@@ -104,19 +75,68 @@ class _NotificationPageState extends State<NotificationPage> {
10475 child: LinearProgressIndicator (),
10576 );
10677 } 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);
10781 return SizedBox ();
10882 }
10983 },
11084 );
11185 }
11286
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 = [];
114119 var length = list.length;
120+ List <Widget > avaterList = [];
121+ final int noOfUser = list.length;
122+ var state = Provider .of <NotificationState >(context);
115123 if (list != null && list.length > 5 ) {
116124 list = list.take (5 ).toList ();
117125 }
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+
120140 var col = Column (
121141 crossAxisAlignment: CrossAxisAlignment .start,
122142 children: < Widget > [
@@ -129,60 +149,80 @@ class _NotificationPageState extends State<NotificationPage> {
129149 istwitterIcon: true ,
130150 size: 25 ),
131151 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),
159153 ],
160154 ),
155+ // names.length > 0 ? Text(names[0]) : SizedBox(),
161156 Padding (
162157 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,
166163 ),
167164 )
168165 ],
169166 );
170167 return col;
171168 }
172169
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+
173195 @override
174196 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+ ),
181223 ),
182- icon: AppIcon .settings,
183- onActionPressed: onSettingIconPressed,
184- ),
185- body: _body (),
224+ Divider (height: 0 , thickness: .6 )
225+ ],
186226 );
187227 }
188228}
0 commit comments