mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 14:29:22 +00:00
Can load older posts on group page
This commit is contained in:
parent
8881ef3af4
commit
c7502e6a04
@ -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/like_widget.dart';
|
||||||
import 'package:comunic/ui/widgets/post_create_form_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/posts_list_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/scroll_watcher.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Authorized group page screen
|
/// Authorized group page screen
|
||||||
@ -35,11 +36,23 @@ class AuthorizedGroupPageScreen extends StatefulWidget {
|
|||||||
class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
|
class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
|
||||||
AdvancedGroupInfo get _group => widget.advancedGroupInfo;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
onRefresh: () => widget.needRefresh(),
|
onRefresh: () => widget.needRefresh(),
|
||||||
child: ListView(
|
child: ListView(
|
||||||
|
controller: _postsController,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildGroupPageHeader(),
|
_buildGroupPageHeader(),
|
||||||
_buildPostCreationArea(),
|
_buildPostCreationArea(),
|
||||||
@ -105,6 +118,7 @@ class _AuthorizedGroupPageScreenState extends State<AuthorizedGroupPageScreen> {
|
|||||||
/// Build the list of posts of the group
|
/// Build the list of posts of the group
|
||||||
Widget _buildGroupPagePostsList() {
|
Widget _buildGroupPagePostsList() {
|
||||||
return PostsListWidget(
|
return PostsListWidget(
|
||||||
|
key: _postsKey,
|
||||||
getPostsList: () => PostsHelper().getGroupPosts(_group.id),
|
getPostsList: () => PostsHelper().getGroupPosts(_group.id),
|
||||||
showPostsTarget: false,
|
showPostsTarget: false,
|
||||||
userNamesClickable: true,
|
userNamesClickable: true,
|
||||||
|
@ -38,10 +38,10 @@ class PostsListWidget extends StatefulWidget {
|
|||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _PostsListWidgetState();
|
State<StatefulWidget> createState() => PostsListWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PostsListWidgetState extends State<PostsListWidget> {
|
class PostsListWidgetState extends State<PostsListWidget> {
|
||||||
// Helpers
|
// Helpers
|
||||||
final UsersHelper _usersHelper = UsersHelper();
|
final UsersHelper _usersHelper = UsersHelper();
|
||||||
final GroupsHelper _groupsHelper = GroupsHelper();
|
final GroupsHelper _groupsHelper = GroupsHelper();
|
||||||
@ -60,7 +60,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_scrollController = ScrollWatcher(onReachBottom: _reachedPostsBottom);
|
_scrollController = ScrollWatcher(onReachBottom: reachedPostsBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -165,7 +165,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
|||||||
|
|
||||||
void _removePost(Post post) => setState(() => _list.remove(post));
|
void _removePost(Post post) => setState(() => _list.remove(post));
|
||||||
|
|
||||||
void _reachedPostsBottom() {
|
void reachedPostsBottom() {
|
||||||
if (widget.getOlder != null) _loadPostsList(getOlder: true);
|
if (widget.getOlder != null) _loadPostsList(getOlder: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user