From 3af5f79992e0600bd5de18b954b126019e7dc9a2 Mon Sep 17 00:00:00 2001 From: Timur Yusupov Date: Fri, 9 Aug 2024 15:08:30 +0400 Subject: [PATCH] return itemCount + 1 logic --- lib/src/loadable/loadable_list_view.dart | 2 -- lib/src/loadable/loadable_paginated_list_view.dart | 12 ++++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/src/loadable/loadable_list_view.dart b/lib/src/loadable/loadable_list_view.dart index 8bd8741..b2e8261 100644 --- a/lib/src/loadable/loadable_list_view.dart +++ b/lib/src/loadable/loadable_list_view.dart @@ -116,8 +116,6 @@ class LoadableListViewState extends State { ), ), // ignore: avoid-returning-widgets - SliverToBoxAdapter(child: buildLastItem(state)), - // ignore: avoid-returning-widgets if (viewModel.footer != null) buildFooter(), ]; } diff --git a/lib/src/loadable/loadable_paginated_list_view.dart b/lib/src/loadable/loadable_paginated_list_view.dart index 3e7db8e..920fca8 100644 --- a/lib/src/loadable/loadable_paginated_list_view.dart +++ b/lib/src/loadable/loadable_paginated_list_view.dart @@ -26,6 +26,14 @@ class LoadablePaginatedListState extends LoadableListViewState { LoadablePaginatedListViewModel get viewModel => widget.viewModel as LoadablePaginatedListViewModel; + @override + Widget buildListItem(int index) { + return index == viewModel.itemCount - 1 + // ignore: avoid-returning-widgets + ? buildLastItem(viewModel.getPaginationState()) + : super.buildListItem(index); + } + @override Widget buildFooter() { return SliverToBoxAdapter( @@ -77,7 +85,7 @@ class LoadablePaginatedListViewModel extends LoadableListViewModel { required super.errorWidget, required super.emptyStateWidget, required super.loadListRequestState, - required super.itemCount, + required int itemCount, required this.loadPageRequestState, required this.errorPageWidget, required this.isAllItemsLoaded, @@ -88,7 +96,7 @@ class LoadablePaginatedListViewModel extends LoadableListViewModel { super.footer, this.loadPage, super.key, - }); + }) : super(itemCount: itemCount + 1); final VoidCallback? loadPage; final Widget errorPageWidget;