1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-24 11:58:51 +00:00

Fix issue with posts list

This commit is contained in:
Pierre HUBERT 2020-05-10 18:48:26 +02:00
parent e3130c9e4b
commit 27a56ae533

View File

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/helpers/posts_helper.dart';
@ -192,7 +194,9 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
Widget _buildListView() {
return RefreshIndicator(
child: ListView.builder(
itemCount: _list.length + _numberTopWidgets,
// We use max function here to display to post notice in case there are not posts to display but there are custom widgets...
itemCount: max(_list.length, 1) + _numberTopWidgets,
itemBuilder: _buildItem,
controller: _scrollController,
),
@ -212,6 +216,9 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
Widget _buildItem(BuildContext context, int index) {
if (index < _numberTopWidgets) return widget.topWidgets[index];
// Show no posts notice if required
if (_list.length == 0) return _buildNoPostNotice();
return PostTile(
post: _list[index - _numberTopWidgets],
usersInfo: _users,
@ -226,7 +233,8 @@ class PostsListWidgetState extends SafeState<PostsListWidget> {
Widget build(BuildContext context) {
if (_error == ErrorLevel.MAJOR) return _buildErrorCard();
if (_list == null) return buildCenteredProgressBar();
if (_list.length == 0) return _buildNoPostNotice();
if (_list.length == 0 && _numberTopWidgets == 0)
return _buildNoPostNotice();
return widget.buildListView ? _buildListView() : _buildColumn();
}