Skip to content

Commit

Permalink
feat: openfoodfacts#2174 - doomscrolling instead of "download more" b…
Browse files Browse the repository at this point in the history
…utton

Impacted file:
* `product_query_page.dart`: now downloading one page before needed; now displaying status for unknown products ("Loading", "Could not load", "Will be loaded later")
  • Loading branch information
monsieurtanuki committed Aug 11, 2022
1 parent 27a823d commit d76a084
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,30 @@ class _ProductQueryPageState extends State<ProductQueryPage>
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(
Expand Down

0 comments on commit d76a084

Please sign in to comment.