From f0a23bcb477f28172b36b192637e2d24d8d9b05c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 16 Apr 2020 08:24:34 +0200 Subject: [PATCH] Display group posts --- lib/helpers/posts_helper.dart | 18 ++++++++++++++++++ .../screens/authorized_group_page_screen.dart | 19 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/helpers/posts_helper.dart b/lib/helpers/posts_helper.dart index 49b9165..8bdac36 100644 --- a/lib/helpers/posts_helper.dart +++ b/lib/helpers/posts_helper.dart @@ -84,6 +84,24 @@ class PostsHelper { } } + /// Get the list of posts of a group + Future getGroupPosts(int groupID, {int from = 0}) async { + final response = await (APIRequest(uri: "posts/get_group", needLogin: true) + ..addInt("groupID", groupID) + ..addInt("startFrom", from == 0 ? 0 : from - 1)) + .exec(); + + if (response.code != 200) return null; + + try { + // Parse & return the list of posts + return PostsList()..addAll(response.getArray().map((f) => _apiToPost(f))); + } catch (e) { + print(e.toString()); + return null; + } + } + /// Get a single post information Future getSingle(int postID) async { final response = await APIRequest( diff --git a/lib/ui/screens/authorized_group_page_screen.dart b/lib/ui/screens/authorized_group_page_screen.dart index 3b1213d..0d84e4a 100644 --- a/lib/ui/screens/authorized_group_page_screen.dart +++ b/lib/ui/screens/authorized_group_page_screen.dart @@ -1,8 +1,10 @@ +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/posts_list_widget.dart'; import 'package:flutter/material.dart'; /// Authorized group page screen @@ -34,12 +36,15 @@ class _AuthorizedGroupPageScreenState extends State { @override Widget build(BuildContext context) { return Column( - children: [_buildGroupPageHeader()], + children: [ + _buildGroupPageHeader(), + Expanded(child: _buildGroupPagePostsList()) + ], ); } /// Build group page header - _buildGroupPageHeader() { + Widget _buildGroupPageHeader() { return Padding( padding: const EdgeInsets.all(8.0), child: Row( @@ -77,4 +82,14 @@ class _AuthorizedGroupPageScreenState extends State { ), ); } + + /// Build the list of posts of the group + Widget _buildGroupPagePostsList() { + return PostsListWidget( + getPostsList: () => PostsHelper().getGroupPosts(_group.id), + showPostsTarget: false, + userNamesClickable: true, + getOlder: (from) => PostsHelper().getGroupPosts(_group.id, from: from), + ); + } }