Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle the duplicates? #254

Closed
nikiforosper opened this issue Mar 2, 2023 · 3 comments
Closed

How to handle the duplicates? #254

nikiforosper opened this issue Mar 2, 2023 · 3 comments

Comments

@nikiforosper
Copy link

nikiforosper commented Mar 2, 2023

Using my api, data is added every second
So, page 1 is loaded and it is ok. But when page 2 loads and new data is added, then page 2 contains some of the data from the page 1.
For example:

  1. Page 1: [1, 2, 3, 4, 5]
  2. Load page 2
  3. Page 1 = [1, 2, 3, 4, 5]
    Page 2 = [4, 5, 6, 7, 8]

My fetch Data function:

Future<void> _fetchPage(int pageKey) async {
    try {
      pg++;
      List<SearchClassified> newClassifieds = await SearchService.searchClassifieds(args, pg);
      bool isLastPage = newClassifieds.length < _pageSize;
      if (isLastPage) {
        _pagingController.appendLastPage(newClassifieds);
      } else {
        final nextPageKey = pageKey + newClassifieds.length;
        _pagingController.appendPage(newClassifieds, nextPageKey);
      }
    } catch (error) {
      if (mounted) {
        _pagingController.error = error;
      }
    }
  }
@clragon
Copy link
Collaborator

clragon commented Mar 3, 2023

you can directly access and set the itemList property of the controller.
you can also remove items from the list you are going to add before adding it, by comparing it against the list of existing items.

@nikiforosper
Copy link
Author

I resolved this with
_pagingController.itemList = _pagingController.itemList?.toSet().toList();

@clragon
Copy link
Collaborator

clragon commented Mar 3, 2023

please close this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants