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

Wrong behavior when reset is called multiple times too fast #77

Open
luis901101 opened this issue Sep 26, 2019 · 2 comments
Open

Wrong behavior when reset is called multiple times too fast #77

luis901101 opened this issue Sep 26, 2019 · 2 comments

Comments

@luis901101
Copy link

I implemented a query search which filters the data shown in a pagewise list while the user is typing in the input text. Every time the user writes a new character in the input text a function is triggered which resets() the PagewiseLoadController to force to fetch new data from page 0... this works fine if the user types slow, but if the text is entered fast then the reset() gets called while there is data being fetched and this produces unexpected duplicated results. This occurs because fetchNewPage is asynchronous and reset doesn't take into account if fetchNewPage is in progress or not, then fetchNewPage could get called twice consecutively and not between resets.

For example:
controller.reset();
controller.reset();

This two calls above should first reset the information of the controller and then fetchNewPage when the _itemBuilder gets called and then again reset the information of the controller and then fetchNewPage when the _itemBuilder gets called again, but instead the reset is called twice consecutively and the fetchNewPage gets called twice consecutively, because as I said the reset is a sync function and the fetchNewPage is an async function.

Solution: the reset function should wait for fetchNewPage to complete in order to do a reset.

@luckv
Copy link

luckv commented Apr 6, 2020

I have the same problem too

@BradyEdgar94
Copy link

I just used the https://pub.dev/packages/debounce_throttle package and it works for me now

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

3 participants