1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 14:59:22 +00:00
comunicmobile/lib/ui/screens/authorized_group_page_screen.dart

131 lines
3.8 KiB
Dart

import 'package:comunic/enums/post_target.dart';
import 'package:comunic/helpers/posts_helper.dart';
import 'package:comunic/models/advanced_group_info.dart';
import 'package:comunic/ui/widgets/group_following_widget.dart';
import 'package:comunic/ui/widgets/group_icon_widget.dart';
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
///
/// This screen is shown when the user is allowed to access to a group's page
///
/// @author Pierre Hubert
class AuthorizedGroupPageScreen extends StatefulWidget {
final AdvancedGroupInfo advancedGroupInfo;
final Function() needRefresh;
const AuthorizedGroupPageScreen({
Key key,
@required this.advancedGroupInfo,
@required this.needRefresh,
}) : assert(advancedGroupInfo != null),
assert(needRefresh != null),
super(key: key);
@override
_AuthorizedGroupPageScreenState createState() =>
_AuthorizedGroupPageScreenState();
}
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(
physics: AlwaysScrollableScrollPhysics(),
controller: _postsController,
children: <Widget>[
_buildGroupPageHeader(),
_buildPostCreationArea(),
_buildGroupPagePostsList()
],
),
);
}
/// Build group page header
Widget _buildGroupPageHeader() {
return Container(
color: Colors.black26,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
GroupIcon(
group: _group,
),
Text(
" ${_group.displayName}",
style: TextStyle(fontSize: 20),
),
Spacer(),
Column(
children: <Widget>[
GroupMembershipWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
Container(
height: 4,
),
GroupFollowingWidget(
group: _group,
onUpdated: () => widget.needRefresh(),
),
Container(
height: 2,
),
LikeWidget(
likeElement: _group,
)
],
)
],
),
),
);
}
/// Add create post target
Widget _buildPostCreationArea() {
if (!_group.canCreatePost) return Container();
return PostCreateFormWidget(
postTarget: PostTarget.GROUP_PAGE,
targetID: _group.id,
onCreated: () => _postsKey.currentState.loadPostsList(getOlder: false));
}
/// Build the list of posts of the group
Widget _buildGroupPagePostsList() {
return PostsListWidget(
key: _postsKey,
getPostsList: () => PostsHelper().getGroupPosts(_group.id),
showPostsTarget: false,
userNamesClickable: true,
getOlder: (from) => PostsHelper().getGroupPosts(_group.id, from: from),
buildListView: false,
);
}
}