1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-25 06:19:22 +00:00
comunicmobile/lib/ui/screens/group_sections/group_posts_section.dart

55 lines
1.6 KiB
Dart
Raw Normal View History

2021-03-16 17:36:17 +00:00
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/post_create_form_widget.dart';
import 'package:comunic/ui/widgets/posts_list_widget.dart';
/// Group posts section
///
/// @author Pierre Hubert
import 'package:flutter/material.dart';
class GroupPostsSection extends StatefulWidget {
final AdvancedGroupInfo group;
const GroupPostsSection({
Key? key,
required this.group,
2022-03-11 16:02:06 +00:00
}) : super(key: key);
2021-03-16 17:36:17 +00:00
@override
_GroupPostsSectionState createState() => _GroupPostsSectionState();
}
class _GroupPostsSectionState extends State<GroupPostsSection> {
final _postsKey = GlobalKey<PostsListWidgetState>();
2022-03-12 08:58:23 +00:00
final _formKey = GlobalKey<PostCreateFormWidgetState>();
2021-03-16 17:36:17 +00:00
/// Add create post target
Widget _buildPostCreationArea() {
if (!widget.group.canCreatePost) return Container();
return PostCreateFormWidget(
2022-03-12 08:58:23 +00:00
key: _formKey,
2021-03-16 17:36:17 +00:00
postTarget: PostTarget.GROUP_PAGE,
targetID: widget.group.id,
onCreated: () => _postsKey.currentState!.loadPostsList(getOlder: false),
2021-03-16 17:36:17 +00:00
);
}
/// Build the list of posts of the group
@override
Widget build(BuildContext context) {
return PostsListWidget(
key: _postsKey,
topWidgets: <Widget>[
_buildPostCreationArea(),
],
getPostsList: () => PostsHelper().getGroupPosts(widget.group.id),
showPostsTarget: false,
userNamesClickable: true,
getOlder: (from) =>
PostsHelper().getGroupPosts(widget.group.id, from: from),
);
}
}