mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 16:25:17 +00:00
Simplify code
This commit is contained in:
53
lib/ui/screens/group_sections/group_posts_section.dart
Normal file
53
lib/ui/screens/group_sections/group_posts_section.dart
Normal file
@ -0,0 +1,53 @@
|
||||
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,
|
||||
}) : assert(group != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_GroupPostsSectionState createState() => _GroupPostsSectionState();
|
||||
}
|
||||
|
||||
class _GroupPostsSectionState extends State<GroupPostsSection> {
|
||||
final _postsKey = GlobalKey<PostsListWidgetState>();
|
||||
|
||||
/// Add create post target
|
||||
Widget _buildPostCreationArea() {
|
||||
if (!widget.group.canCreatePost) return Container();
|
||||
|
||||
return PostCreateFormWidget(
|
||||
postTarget: PostTarget.GROUP_PAGE,
|
||||
targetID: widget.group.id,
|
||||
onCreated: () => _postsKey.currentState.loadPostsList(getOlder: false),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user