Skip to content

Commit 21d341f

Browse files
committed
🗃️ Change following list schema
1.:card_file_box: Following db tabale is moved in profile table. 2.:fire: Fetch following method removed. 3.:zap: FOllowing widget changed to statless widget. 4. :sparkles: Add view profile of follower/ following. 5.:sparkles: Add user list view who liked tweet. 6.:sparkles: Add nested profile view feature.
1 parent c840552 commit 21d341f

File tree

8 files changed

+154
-196
lines changed

8 files changed

+154
-196
lines changed

lib/helper/utility.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:firebase_analytics/firebase_analytics.dart';
22
import 'package:firebase_database/firebase_database.dart';
3+
import 'package:flutter/foundation.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
56
import 'package:flutter_twitter_clone/widgets/newWidget/customLoader.dart';
@@ -170,7 +171,12 @@ void cprint(dynamic data, {String errorIn, String event}) {
170171
}
171172

172173
void logEvent(String event, {Map<String, dynamic> parameter}) {
173-
kAnalytics.logEvent(name: event, parameters: parameter);
174+
kReleaseMode ? kAnalytics.logEvent(name: event, parameters: parameter) : print("[EVENT]: $event");
175+
}
176+
177+
void debugLog(String log, {dynamic param = ""}){
178+
final String time = DateFormat("mm:ss:mmm").format(DateTime.now());
179+
print("[$time][Log]: $log, $param");
174180
}
175181

176182
void share(String message, {String subject}) {

lib/model/user.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class User {
6565
});
6666
}
6767
followers = followersList != null ? followersList.length : null;
68+
if(map['followingList'] != null){
69+
followingList = List<String>();
70+
map['followingList'].forEach((value){
71+
followingList.add(value);
72+
});
73+
}
74+
following = followingList != null ? followingList.length : null;
6875
}
6976
toJson() {
7077
return {
@@ -80,11 +87,12 @@ class User {
8087
'location': location,
8188
'createdAt': createdAt,
8289
'followers': followersList != null ? followersList.length : null,
83-
'following': following,
90+
'following': followersList!= null ? followersList.length : null,
8491
'userName': userName,
8592
'webSite': webSite,
8693
'isVerified': isVerified ?? false,
87-
'followerList' : followersList
94+
'followerList' : followersList,
95+
'followingList':followingList
8896
};
8997
}
9098

@@ -104,7 +112,7 @@ class User {
104112
int following,
105113
String webSite,
106114
bool isVerified,
107-
List<String> followingList
115+
List<String> followingList,
108116
}) {
109117
return User(
110118
email: email ?? this.email,
@@ -122,7 +130,7 @@ class User {
122130
userId: userId ?? this.userId,
123131
userName: userName ?? this.userName,
124132
webSite: webSite ?? this.webSite,
125-
followersList: followersList ?? this.followersList
133+
followersList: followersList ?? this.followersList,
126134
);
127135
}
128136

lib/page/common/sidebar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class _SidebarMenuState extends State<SidebarMenu> {
118118
return InkWell(
119119
onTap: () {
120120
var authstate = Provider.of<AuthState>(context);
121-
authstate.profileFollowingList = [];
121+
// authstate.profileFollowingList = [];
122122
authstate.getProfileUser();
123123
_navigateTo(navigateTo);
124124
},

lib/page/common/widget/userListWidget.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ class UserListWidget extends StatelessWidget {
3434
children: <Widget>[
3535
ListTile(
3636
onTap: () {
37-
// Navigator.of(context).pushNamed('/ProfilePage/' + user?.userId);
37+
Navigator.of(context).pushNamed('/ProfilePage/' + user?.userId);
3838
},
3939
leading: RippleButton(
40+
onPressed: () {
41+
Navigator.of(context)
42+
.pushNamed('/ProfilePage/' + user?.userId);
43+
},
4044
borderRadius: BorderRadius.all(Radius.circular(60)),
4145
child: customImage(context, user.profilePic, height: 60),
4246
),

lib/page/feed/feedPage.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class _FeedPageState extends State<FeedPage> {
6969
if (!state.isBusy && state.feedlist != null && state.feedlist.isNotEmpty) {
7070
list = state.feedlist.where((x) {
7171
if (x.user.userId == authstate.userId ||
72-
(authstate.userfollowingList != null &&
73-
authstate.userfollowingList.contains(x.user.userId))) {
72+
(authstate.userModel?.followingList != null &&
73+
authstate.userModel.followingList.contains(x.user.userId))) {
7474
return true;
7575
} else {
7676
return false;

lib/page/profile/follow/followingListPage.dart

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,13 @@ import 'package:flutter_twitter_clone/page/common/usersListPage.dart';
44
import 'package:flutter_twitter_clone/state/authState.dart';
55
import 'package:provider/provider.dart';
66

7-
class FollowingListPage extends StatefulWidget {
8-
FollowingListPage({Key key}) : super(key: key);
9-
10-
@override
11-
_FollowingListPageState createState() => _FollowingListPageState();
12-
}
13-
14-
class _FollowingListPageState extends State<FollowingListPage> {
15-
@override
16-
void initState() {
17-
var authstate = Provider.of<AuthState>(context, listen: false);
18-
super.initState();
19-
WidgetsBinding.instance.addPostFrameCallback((_) {
20-
authstate.getFollowingUser();
21-
});
22-
}
23-
7+
class FollowingListPage extends StatelessWidget {
248
@override
259
Widget build(BuildContext context) {
2610
var state = Provider.of<AuthState>(context);
2711
return UsersListPage(
28-
pageTitle: 'Followers',
29-
userList: state.profileFollowingList,
12+
pageTitle: 'Following',
13+
userList: state.profileUserModel.followingList,
3014
appBarIcon: AppIcon.follow,
3115
emptyScreenText:
3216
'${state?.profileUserModel?.userName ?? state.userModel.userName} isn\'t follow anyone',

lib/page/profile/profilePage.dart

Lines changed: 79 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class _ProfilePageState extends State<ProfilePage> {
4949
iconTheme: IconThemeData(color: Colors.white),
5050
backgroundColor: Colors.transparent,
5151
actions: <Widget>[
52-
authstate.profileUserModel == null
52+
authstate.isbusy
5353
? SizedBox.shrink()
5454
: PopupMenuButton<Choice>(
5555
onSelected: (d) {},
@@ -64,7 +64,7 @@ class _ProfilePageState extends State<ProfilePage> {
6464
),
6565
],
6666
flexibleSpace: FlexibleSpaceBar(
67-
background: authstate.profileUserModel == null
67+
background: authstate.isbusy
6868
? SizedBox.shrink()
6969
: Stack(
7070
children: <Widget>[
@@ -235,6 +235,17 @@ class _ProfilePageState extends State<ProfilePage> {
235235
}
236236
}
237237

238+
/// This meathod called when user pressed back button
239+
/// When profile page is about to close
240+
/// Maintain minimum user's profile in profile page list
241+
Future<bool> _onWillPop() async {
242+
final state = Provider.of<AuthState>(context, listen: false);
243+
244+
/// It will remove last user's profile from profileUserModelList
245+
state.removeLastUser();
246+
return true;
247+
}
248+
238249
@override
239250
Widget build(BuildContext context) {
240251
var state = Provider.of<FeedState>(context);
@@ -244,72 +255,74 @@ class _ProfilePageState extends State<ProfilePage> {
244255
if (state.feedlist != null && state.feedlist.length > 0) {
245256
list = state.feedlist.where((x) => x.userId == id).toList();
246257
}
247-
return Scaffold(
248-
backgroundColor: list != null && list.isNotEmpty
249-
? TwitterColor.mystic
250-
: TwitterColor.white,
251-
floatingActionButton: isMyProfile ? _floatingActionButton() : null,
252-
body: CustomScrollView(
253-
physics: ClampingScrollPhysics(),
254-
slivers: <Widget>[
255-
getAppbar(),
256-
authstate.profileUserModel == null
257-
? _emptyBox()
258-
: SliverToBoxAdapter(
259-
child: Container(
260-
color: Colors.white,
261-
child: authstate.profileUserModel == null
262-
? SizedBox.shrink()
263-
: UserNameRowWidget(
264-
user: authstate.profileUserModel,
265-
isMyProfile: isMyProfile,
266-
),
267-
),
268-
),
269-
SliverList(
270-
delegate: SliverChildListDelegate(
271-
authstate.profileUserModel == null
272-
? [
273-
Container(
274-
height: fullHeight(context) - 180,
275-
child: CustomScreenLoader(
276-
height: double.infinity,
277-
width: fullWidth(context),
278-
backgroundColor: Colors.white,
279-
)
280-
)
281-
]
282-
: list == null || list.length < 1
283-
? [
284-
Container(
285-
padding:
286-
EdgeInsets.only(top: 50, left: 30, right: 30),
287-
child: NotifyText(
288-
title: isMyProfile
289-
? 'You haven\'t post any Tweet yet'
290-
: '${authstate.profileUserModel.userName} hasn\'t Tweeted yet',
291-
subTitle: isMyProfile
292-
? 'Tap tweet button to add new'
293-
: 'Once he\'ll do, they will be shown up here',
258+
return WillPopScope(
259+
onWillPop: _onWillPop,
260+
child: Scaffold(
261+
backgroundColor: list != null && list.isNotEmpty
262+
? TwitterColor.mystic
263+
: TwitterColor.white,
264+
floatingActionButton: isMyProfile ? _floatingActionButton() : null,
265+
body: CustomScrollView(
266+
physics: ClampingScrollPhysics(),
267+
slivers: <Widget>[
268+
getAppbar(),
269+
authstate.isbusy
270+
? _emptyBox()
271+
: SliverToBoxAdapter(
272+
child: Container(
273+
color: Colors.white,
274+
child: authstate.isbusy
275+
? SizedBox.shrink()
276+
: UserNameRowWidget(
277+
user: authstate.profileUserModel,
278+
isMyProfile: isMyProfile,
294279
),
295-
)
296-
]
297-
: list
298-
.map(
299-
(x) => Container(
300-
color: TwitterColor.white,
301-
child: Tweet(
302-
model: x,
303-
isDisplayOnProfile: true,
304-
trailing: TweetBottomSheet().tweetOptionIcon(
305-
context, x, TweetType.Tweet),
280+
),
281+
),
282+
SliverList(
283+
delegate: SliverChildListDelegate(
284+
authstate.isbusy
285+
? [
286+
Container(
287+
height: fullHeight(context) - 180,
288+
child: CustomScreenLoader(
289+
height: double.infinity,
290+
width: fullWidth(context),
291+
backgroundColor: Colors.white,
292+
))
293+
]
294+
: list == null || list.length < 1
295+
? [
296+
Container(
297+
padding:
298+
EdgeInsets.only(top: 50, left: 30, right: 30),
299+
child: NotifyText(
300+
title: isMyProfile
301+
? 'You haven\'t post any Tweet yet'
302+
: '${authstate.profileUserModel.userName} hasn\'t Tweeted yet',
303+
subTitle: isMyProfile
304+
? 'Tap tweet button to add new'
305+
: 'Once he\'ll do, they will be shown up here',
306306
),
307-
),
308-
)
309-
.toList(),
310-
),
311-
)
312-
],
307+
)
308+
]
309+
: list
310+
.map(
311+
(x) => Container(
312+
color: TwitterColor.white,
313+
child: Tweet(
314+
model: x,
315+
isDisplayOnProfile: true,
316+
trailing: TweetBottomSheet().tweetOptionIcon(
317+
context, x, TweetType.Tweet),
318+
),
319+
),
320+
)
321+
.toList(),
322+
),
323+
)
324+
],
325+
),
313326
),
314327
);
315328
}

0 commit comments

Comments
 (0)