mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 00:05:16 +00:00
Display user posts
This commit is contained in:
@ -19,13 +19,16 @@ import 'package:flutter/material.dart';
|
||||
class PostsListWidget extends StatefulWidget {
|
||||
final Future<PostsList> Function() getPostsList;
|
||||
final bool showPostsTarget;
|
||||
final bool buildListView;
|
||||
|
||||
const PostsListWidget({
|
||||
Key key,
|
||||
@required this.getPostsList,
|
||||
@required this.showPostsTarget,
|
||||
this.buildListView = true,
|
||||
}) : assert(getPostsList != null),
|
||||
assert(showPostsTarget != null),
|
||||
assert(buildListView != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
@ -67,7 +70,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
||||
|
||||
final groups = await _groupsHelper.getList(list.groupsID);
|
||||
|
||||
if(groups == null) return _loadError();
|
||||
if (groups == null) return _loadError();
|
||||
|
||||
setState(() {
|
||||
_list = list;
|
||||
@ -83,13 +86,26 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
||||
Widget _buildListView() {
|
||||
return ListView.builder(
|
||||
itemCount: _list.length,
|
||||
itemBuilder: (c, i) => PostTile(
|
||||
post: _list[i],
|
||||
usersInfo: _users,
|
||||
groupsInfo: _groups,
|
||||
onDeletedPost: _removePost,
|
||||
showPostTarget: widget.showPostsTarget,
|
||||
),
|
||||
itemBuilder: _buildItem,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildColumn() {
|
||||
return Column(
|
||||
children: List.generate(
|
||||
_list.length,
|
||||
(i) => _buildItem(null, i),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, int index) {
|
||||
return PostTile(
|
||||
post: _list[index],
|
||||
usersInfo: _users,
|
||||
groupsInfo: _groups,
|
||||
onDeletedPost: _removePost,
|
||||
showPostTarget: widget.showPostsTarget,
|
||||
);
|
||||
}
|
||||
|
||||
@ -97,7 +113,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
if (_error == ErrorLevel.MAJOR) return _buildErrorCard();
|
||||
if (_list == null) return buildCenteredProgressBar();
|
||||
return _buildListView();
|
||||
return widget.buildListView ? _buildListView() : _buildColumn();
|
||||
}
|
||||
|
||||
void _removePost(Post post) => setState(() => _list.remove(post));
|
||||
|
Reference in New Issue
Block a user