diff --git a/packages/smooth_app/lib/pages/product/common/product_query_page.dart b/packages/smooth_app/lib/pages/product/common/product_query_page.dart index fb6970f27cb..d855d7df7b5 100644 --- a/packages/smooth_app/lib/pages/product/common/product_query_page.dart +++ b/packages/smooth_app/lib/pages/product/common/product_query_page.dart @@ -219,13 +219,30 @@ class _ProductQueryPageState extends State return _getTopMessagesCard(); } index--; - // TODO(monsieurtanuki): maybe call it earlier, like for first unknown page index - 5? - if (index >= _model.displayBarcodes.length) { - _downloadNextPage(); + const int numberOfPagesBeforeDownload = 1; + const int numberOfDownloadingPages = 1; + // if not all products are already downloaded + if (_model.supplier.partialProductList.totalSize > + _model.displayBarcodes.length) { + if (index >= + _model.displayBarcodes.length - + numberOfPagesBeforeDownload * + _model.supplier.productQuery.pageSize) { + _downloadNextPage(); + } + } + if (index >= + _model.displayBarcodes.length + + numberOfDownloadingPages * + _model.supplier.productQuery.pageSize) { + return const SmoothProductCardTemplate( + message: 'Will be loaded later', + ); } if (index >= _model.displayBarcodes.length) { - // TODO(monsieurtanuki): maybe display something specific for data being downloaded (the next page) and unknown data (beyond next page) - return const SmoothProductCardTemplate(); + return SmoothProductCardTemplate( + message: _loadingNext ? 'Loading...' : 'Could not load', + ); } return Padding( padding: const EdgeInsets.symmetric(