From 27a56ae533475d830ccd36088b0b53442a51de91 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 10 May 2020 18:48:26 +0200 Subject: [PATCH] Fix issue with posts list --- lib/ui/widgets/posts_list_widget.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ui/widgets/posts_list_widget.dart b/lib/ui/widgets/posts_list_widget.dart index 7cfe8b7..fdc0ebd 100644 --- a/lib/ui/widgets/posts_list_widget.dart +++ b/lib/ui/widgets/posts_list_widget.dart @@ -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 { 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 { 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 { 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(); }