Skip to content

Commit aff6527

Browse files
committed
⚡ improve performance on user list page
1.:bug:(fix) Restrict composing empty Tweet from imageview page. 2. USer list is now fething from search page on userlist page.
1 parent 0e5f8ab commit aff6527

File tree

9 files changed

+68
-63
lines changed

9 files changed

+68
-63
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
## [1.0.3] - UPCOMMING
1+
## [1.0.4] - UPCOMMING
22

33
* User sort feature added on user search page.
44
* Added pull to refresh on search page.
55
* Newest Tweet will show first in Tweet list.
66
* Newest comment tweet will show first in comment Tweet list.
77

8-
## [1.0.2] - 31 Mar 2020
8+
## [1.0.3] - 31 Mar 2020
99

1010
* Google login failed bug fix
1111
* Email login at first time bug fix.

lib/page/common/usersListPage.dart

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_twitter_clone/helper/theme.dart';
3+
import 'package:flutter_twitter_clone/model/user.dart';
34
import 'package:flutter_twitter_clone/page/common/widget/userListWidget.dart';
45
import 'package:flutter_twitter_clone/state/authState.dart';
6+
import 'package:flutter_twitter_clone/state/searchState.dart';
57
import 'package:flutter_twitter_clone/widgets/customAppBar.dart';
68
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
79
import 'package:provider/provider.dart';
@@ -12,16 +14,17 @@ class UsersListPage extends StatelessWidget {
1214
this.pageTitle = "",
1315
this.appBarIcon,
1416
this.emptyScreenText,
15-
this.emptyScreenSubTileText,
16-
this.userList,
17+
this.emptyScreenSubTileText,
18+
this.userIdsList,
1719
}) : super(key: key);
1820

1921
final String pageTitle;
2022
final String emptyScreenText;
2123
final String emptyScreenSubTileText;
2224
final int appBarIcon;
23-
final List<String> userList;
25+
final List<String> userIdsList;
2426

27+
List<User> userList;
2528
@override
2629
Widget build(BuildContext context) {
2730
return Scaffold(
@@ -30,13 +33,18 @@ class UsersListPage extends StatelessWidget {
3033
isBackButton: true,
3134
title: customTitleText(pageTitle),
3235
icon: appBarIcon),
33-
body: Consumer<AuthState>(
36+
body: Consumer<SearchState>(
3437
builder: (context, state, child) {
35-
return UserListWidget(
36-
list: userList,
37-
emptyScreenText: emptyScreenText,
38-
emptyScreenSubTileText: emptyScreenSubTileText,
39-
);
38+
if (userIdsList != null) {
39+
userList = state.getuserDetail(userIdsList);
40+
}
41+
return userList == null
42+
? LinearProgressIndicator()
43+
: UserListWidget(
44+
list: userList,
45+
emptyScreenText: emptyScreenText,
46+
emptyScreenSubTileText: emptyScreenSubTileText,
47+
);
4048
},
4149
),
4250
);

lib/page/common/widget/userListWidget.dart

+17-44
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import 'package:flutter_twitter_clone/model/user.dart';
55
import 'package:flutter_twitter_clone/state/authState.dart';
66
import 'package:flutter_twitter_clone/state/feedState.dart';
77
import 'package:flutter_twitter_clone/state/notificationState.dart';
8+
import 'package:flutter_twitter_clone/state/searchState.dart';
89
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
910
import 'package:flutter_twitter_clone/widgets/newWidget/customUrlText.dart';
1011
import 'package:flutter_twitter_clone/widgets/newWidget/emptyList.dart';
1112
import 'package:flutter_twitter_clone/widgets/newWidget/rippleButton.dart';
1213
import 'package:provider/provider.dart';
1314

1415
class UserListWidget extends StatelessWidget {
15-
final List<String> list;
16+
final List<User> list;
1617
final String emptyScreenText;
1718
final String emptyScreenSubTileText;
1819
UserListWidget({
@@ -26,49 +27,21 @@ class UserListWidget extends StatelessWidget {
2627
Widget build(BuildContext context) {
2728
var state = Provider.of<AuthState>(context, listen: false);
2829
String myId = state.userModel.key;
29-
return list != null && list.isNotEmpty
30-
? ListView.separated(
31-
itemBuilder: (context, index) {
32-
return FutureBuilder(
33-
future: state.getuserDetail(list[index]),
34-
builder: (context, AsyncSnapshot<User> snapshot) {
35-
if (snapshot.hasData) {
36-
return UserTile(
37-
user: snapshot.data,
38-
myId: myId,
39-
);
40-
} else if (index == 0) {
41-
return Container(
42-
child: SizedBox(
43-
height: 3,
44-
child: LinearProgressIndicator(),
45-
));
46-
} else {
47-
return SizedBox.shrink();
48-
}
49-
},
50-
);
51-
},
52-
separatorBuilder: (context, index) {
53-
return Divider(
54-
height: 0,
55-
);
56-
},
57-
itemCount: list.length,
58-
)
59-
: state.isbusy
60-
? SizedBox(
61-
height: 3,
62-
child: LinearProgressIndicator(),
63-
)
64-
: Container(
65-
width: fullWidth(context),
66-
padding: EdgeInsets.only(top: 0, left: 30, right: 30),
67-
child: NotifyText(
68-
title: emptyScreenText,
69-
subTitle: emptyScreenSubTileText,
70-
),
71-
);
30+
return ListView.separated(
31+
itemBuilder: (context, index) {
32+
return UserTile(
33+
user: list[index],
34+
myId: myId,
35+
);
36+
},
37+
separatorBuilder: (context, index) {
38+
return Divider(
39+
height: 0,
40+
);
41+
},
42+
itemCount: list.length,
43+
);
44+
// : LinearProgressIndicator();
7245
}
7346
}
7447

lib/page/feed/imageViewPage.dart

+6
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ class _ImageViewPgeState extends State<ImageViewPge> {
157157
}
158158

159159
void _submitButton() {
160+
if(_textEditingController.text == null || _textEditingController.text.isEmpty){
161+
return;
162+
}
163+
if(_textEditingController.text.length > 280){
164+
return ;
165+
}
160166
var state = Provider.of<FeedState>(context);
161167
var authState = Provider.of<AuthState>(context);
162168
var user = authState.userModel;

lib/page/profile/follow/followerListPage.dart

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ class FollowerListPage extends StatelessWidget {
1010
Widget build(BuildContext context) {
1111
var state = Provider.of<AuthState>(context);
1212
return UsersListPage(
13-
pageTitle: 'Followers',
14-
userList: state.profileUserModel?.followersList,
15-
appBarIcon:AppIcon.follow,
16-
emptyScreenText: '${state?.profileUserModel?.userName ?? state.userModel.userName} doesn\'t have any followers',
17-
emptyScreenSubTileText: 'When someone follow them, they\'ll be listed here.',
13+
pageTitle: 'Followers',
14+
userIdsList: state.profileUserModel?.followersList,
15+
appBarIcon: AppIcon.follow,
16+
emptyScreenText:
17+
'${state?.profileUserModel?.userName ?? state.userModel.userName} doesn\'t have any followers',
18+
emptyScreenSubTileText:
19+
'When someone follow them, they\'ll be listed here.',
1820
);
1921
}
2022
}

lib/page/profile/follow/followingListPage.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FollowingListPage extends StatelessWidget {
1010
var state = Provider.of<AuthState>(context);
1111
return UsersListPage(
1212
pageTitle: 'Following',
13-
userList: state.profileUserModel.followingList,
13+
userIdsList: state.profileUserModel.followingList,
1414
appBarIcon: AppIcon.follow,
1515
emptyScreenText:
1616
'${state?.profileUserModel?.userName ?? state.userModel.userName} isn\'t follow anyone',

lib/state/authState.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ class AuthState extends AppState {
314314
cprint(error, errorIn: 'updateUserProfile');
315315
}
316316
}
317-
317+
318+
318319
/// `Fetch` user `detail` whoose userId is passed
319320
Future<User> getuserDetail(String userId) async {
320321
User user;

lib/state/searchState.dart

+15
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,19 @@ class SearchState extends AppState {
125125
return "Unknown";
126126
}
127127
}
128+
/// Return user list relative to provided `userIds`
129+
/// Method is used on
130+
List<User> userList = [];
131+
List<User> getuserDetail(List<String> userIds){
132+
final list = _userlist.where((x) {
133+
if(userIds.contains(x.key)){
134+
return true;
135+
}
136+
else{
137+
return false;
138+
}
139+
140+
}).toList();
141+
return list;
142+
}
128143
}

lib/widgets/tweet/widgets/tweetIconsRow.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class TweetIconsRow extends StatelessWidget {
235235
CustomRoute<bool>(
236236
builder: (BuildContext context) => UsersListPage(
237237
pageTitle: "Liked by",
238-
userList: model.likeList.map((x) => x.userId).toList(),
238+
userIdsList: model.likeList.map((x) => x.userId).toList(),
239239
),
240240
),
241241
);

0 commit comments

Comments
 (0)