1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 06:19:22 +00:00

Can load older posts on group page

This commit is contained in:
Pierre HUBERT 2020-04-16 09:07:23 +02:00
parent 8881ef3af4
commit c7502e6a04
2 changed files with 18 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import 'package:comunic/ui/widgets/group_membership_widget.dart';
import 'package:comunic/ui/widgets/like_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:flutter/material.dart';
/// Authorized group page screen
@ -35,11 +36,23 @@ class AuthorizedGroupPageScreen extends StatefulWidget {
class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
AdvancedGroupInfo get _group => widget.advancedGroupInfo;
// Allows load older posts when we reach the bottom of the page
final _postsKey = GlobalKey<PostsListWidgetState>();
ScrollWatcher _postsController;
@override
void initState() {
_postsController = ScrollWatcher(
onReachBottom: () => _postsKey.currentState.reachedPostsBottom());
super.initState();
}
@override
Widget build(BuildContext context) {
return RefreshIndicator(
onRefresh: () => widget.needRefresh(),
child: ListView(
controller: _postsController,
children: <Widget>[
_buildGroupPageHeader(),
_buildPostCreationArea(),
@ -105,6 +118,7 @@ class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
/// Build the list of posts of the group
Widget _buildGroupPagePostsList() {
return PostsListWidget(
key: _postsKey,
getPostsList: () => PostsHelper().getGroupPosts(_group.id),
showPostsTarget: false,
userNamesClickable: true,

View File

@ -38,10 +38,10 @@ class PostsListWidget extends StatefulWidget {
super(key: key);
@override
State<StatefulWidget> createState() => _PostsListWidgetState();
State<StatefulWidget> createState() => PostsListWidgetState();
}
class _PostsListWidgetState extends State<PostsListWidget> {
class PostsListWidgetState extends State<PostsListWidget> {
// Helpers
final UsersHelper _usersHelper = UsersHelper();
final GroupsHelper _groupsHelper = GroupsHelper();
@ -60,7 +60,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
void initState() {
super.initState();
_scrollController = ScrollWatcher(onReachBottom: _reachedPostsBottom);
_scrollController = ScrollWatcher(onReachBottom: reachedPostsBottom);
}
@override
@ -165,7 +165,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
void _removePost(Post post) => setState(() => _list.remove(post));
void _reachedPostsBottom() {
void reachedPostsBottom() {
if (widget.getOlder != null) _loadPostsList(getOlder: true);
}
}