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

[scrollable_positioned_list] package - first and last index swap after fast scrolling #541

Open
slymnyg opened this issue Sep 20, 2024 · 3 comments

Comments

@slymnyg
Copy link

slymnyg commented Sep 20, 2024

Problem description

The issue is with the scrollable_positioned_list package. I am using it to get the first and last visible item indexes in the list, but there is a problem where these indexes are swapped after fast scrolling.

Steps to reproduce

  1. Use the scrollable_positioned_list package in a Flutter app.
  2. Set up a listener for itemPositionsListener.itemPositions to track first and last indexes and log them to the console as follows:

itemPositionsListener.itemPositions.addListener(() async {
final positions = itemPositionsListener.itemPositions.value;
if (positions.isEmpty) {
return;
}
final newFirstIndex = positions.first.index;
final newLastIndex = positions.last.index;
print('First index: $newFirstIndex, Last index: $newLastIndex');
});

  1. Scroll the list slowly in one direction.
  2. Quickly scroll back up.
  3. Check the console log to observe that the first index and last index are swapped after fast scrolling.

The issue occurs consistently when performing these steps.

Expected behavior

The first index should represent the first visible item at the top of the screen, and the last index should represent the last visible item at the bottom.

Actual behavior

After quickly scrolling back up, the first index displays the index of the last item at the bottom of the screen, and the last index shows the index of the first item at the top of the screen. This persists until the indexes equalize, after which it works correctly again.

Environment

scrollable_positioned_list : ^0.3.8
flutter: 3.24.2

Video Demonstration:

ScreenRecording_09-20-2024.16-05-45_1.MP4
@slymnyg slymnyg changed the title []package - first and last index swap after fast scrolling [scrollable_positioned_list] package - first and last index swap after fast scrolling Sep 20, 2024
@minhtritc97
Copy link

same issue, package work correctly if user scroll slowly but fast scrolling then it's incorrect

@minhtritc97
Copy link

i found solution to resolved this issue, just add line
VisibilityDetectorController.instance.updateInterval = Duration.zero;
It was mentioned in the document, but I missed it

@khanhduy122
Copy link

final positions = itemPositionsListener.itemPositions.value.toList();
positions.sort((a, b) => a.index.compareTo(b.index));
my case is almost the same. this code solved my problem you should try it

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