diff --git a/lib/ui/screens/authorized_group_page_screen.dart b/lib/ui/screens/authorized_group_page_screen.dart index ba4e8ce..0226051 100644 --- a/lib/ui/screens/authorized_group_page_screen.dart +++ b/lib/ui/screens/authorized_group_page_screen.dart @@ -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 { AdvancedGroupInfo get _group => widget.advancedGroupInfo; + // Allows load older posts when we reach the bottom of the page + final _postsKey = GlobalKey(); + 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: [ _buildGroupPageHeader(), _buildPostCreationArea(), @@ -105,6 +118,7 @@ class _AuthorizedGroupPageScreenState extends State { /// Build the list of posts of the group Widget _buildGroupPagePostsList() { return PostsListWidget( + key: _postsKey, getPostsList: () => PostsHelper().getGroupPosts(_group.id), showPostsTarget: false, userNamesClickable: true, diff --git a/lib/ui/widgets/posts_list_widget.dart b/lib/ui/widgets/posts_list_widget.dart index 96c7b42..a8af9e5 100644 --- a/lib/ui/widgets/posts_list_widget.dart +++ b/lib/ui/widgets/posts_list_widget.dart @@ -38,10 +38,10 @@ class PostsListWidget extends StatefulWidget { super(key: key); @override - State createState() => _PostsListWidgetState(); + State createState() => PostsListWidgetState(); } -class _PostsListWidgetState extends State { +class PostsListWidgetState extends State { // Helpers final UsersHelper _usersHelper = UsersHelper(); final GroupsHelper _groupsHelper = GroupsHelper(); @@ -60,7 +60,7 @@ class _PostsListWidgetState extends State { void initState() { super.initState(); - _scrollController = ScrollWatcher(onReachBottom: _reachedPostsBottom); + _scrollController = ScrollWatcher(onReachBottom: reachedPostsBottom); } @override @@ -165,7 +165,7 @@ class _PostsListWidgetState extends State { void _removePost(Post post) => setState(() => _list.remove(post)); - void _reachedPostsBottom() { + void reachedPostsBottom() { if (widget.getOlder != null) _loadPostsList(getOlder: true); } }