Skip to content

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

@slymnyg

Description

@slymnyg

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions