mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Improve user page performances
This commit is contained in:
parent
edff7868f2
commit
f41983304a
@ -6,7 +6,6 @@ import 'package:comunic/ui/routes/main_route/main_route.dart';
|
||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
|
||||
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
|
||||
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
||||
import 'package:comunic/ui/widgets/scroll_watcher.dart';
|
||||
import 'package:comunic/utils/conversations_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -42,19 +41,8 @@ class _UserPageScreenState extends State<UserPageScreen> {
|
||||
GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
|
||||
GlobalKey<RefreshIndicatorState>();
|
||||
|
||||
// Scroll detection (to load more user posts automatically)
|
||||
final _postListKey = GlobalKey<PostsListWidgetState>();
|
||||
ScrollWatcher _scrollWatcher;
|
||||
|
||||
_setStatus(_PageStatus s) => setState(() => _status = s);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_scrollWatcher = ScrollWatcher(
|
||||
onReachBottom: () => _postListKey.currentState.reachedPostsBottom());
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
@ -92,13 +80,7 @@ class _UserPageScreenState extends State<UserPageScreen> {
|
||||
return Scaffold(
|
||||
body: RefreshIndicator(
|
||||
key: _refreshIndicatorKey,
|
||||
child: ListView(
|
||||
children: <Widget>[]
|
||||
..add(_buildHeader())
|
||||
..addAll(_buildBody()),
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
controller: _scrollWatcher,
|
||||
),
|
||||
child: _buildBody(),
|
||||
onRefresh: _getUserInfo,
|
||||
),
|
||||
);
|
||||
@ -161,27 +143,22 @@ class _UserPageScreenState extends State<UserPageScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildBody() {
|
||||
return <Widget>[
|
||||
// Posts create form
|
||||
_userInfo.canPostTexts
|
||||
? PostCreateFormWidget(
|
||||
postTarget: PostTarget.USER_PAGE,
|
||||
targetID: _userInfo.id,
|
||||
onCreated: _postCreated,
|
||||
)
|
||||
: Container(),
|
||||
|
||||
// Posts list
|
||||
PostsListWidget(
|
||||
key: _postListKey,
|
||||
getPostsList: () => _postsHelper.getUserPosts(widget.userID),
|
||||
getOlder: (from) =>
|
||||
_postsHelper.getUserPosts(widget.userID, from: from),
|
||||
showPostsTarget: false,
|
||||
buildListView: false,
|
||||
),
|
||||
];
|
||||
Widget _buildBody() {
|
||||
return PostsListWidget(
|
||||
topWidgets: [
|
||||
_buildHeader(),
|
||||
_userInfo.canPostTexts
|
||||
? PostCreateFormWidget(
|
||||
postTarget: PostTarget.USER_PAGE,
|
||||
targetID: _userInfo.id,
|
||||
onCreated: _postCreated,
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
getPostsList: () => _postsHelper.getUserPosts(widget.userID),
|
||||
getOlder: (from) => _postsHelper.getUserPosts(widget.userID, from: from),
|
||||
showPostsTarget: false,
|
||||
);
|
||||
}
|
||||
|
||||
/// Method called each time a menu option is selected
|
||||
|
@ -22,6 +22,7 @@ import 'package:flutter/material.dart';
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class PostsListWidget extends StatefulWidget {
|
||||
final List<Widget> topWidgets;
|
||||
final Future<PostsList> Function() getPostsList;
|
||||
final Future<PostsList> Function(int from) getOlder;
|
||||
final bool showPostsTarget;
|
||||
@ -35,6 +36,7 @@ class PostsListWidget extends StatefulWidget {
|
||||
this.userNamesClickable = true,
|
||||
this.buildListView = true,
|
||||
this.getOlder,
|
||||
this.topWidgets,
|
||||
}) : assert(getPostsList != null),
|
||||
assert(showPostsTarget != null),
|
||||
assert(buildListView != null),
|
||||
@ -62,6 +64,9 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
||||
|
||||
set error(ErrorLevel err) => setState(() => _error = err);
|
||||
|
||||
int get _numberTopWidgets =>
|
||||
widget.topWidgets == null ? 0 : widget.topWidgets.length;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -187,7 +192,7 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
||||
Widget _buildListView() {
|
||||
return RefreshIndicator(
|
||||
child: ListView.builder(
|
||||
itemCount: _list.length,
|
||||
itemCount: _list.length + _numberTopWidgets,
|
||||
itemBuilder: _buildItem,
|
||||
controller: _scrollController,
|
||||
),
|
||||
@ -205,8 +210,10 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, int index) {
|
||||
if (index < _numberTopWidgets) return widget.topWidgets[index];
|
||||
|
||||
return PostTile(
|
||||
post: _list[index],
|
||||
post: _list[index - _numberTopWidgets],
|
||||
usersInfo: _users,
|
||||
groupsInfo: _groups,
|
||||
onDeletedPost: _removePost,
|
||||
|
Loading…
Reference in New Issue
Block a user