Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/flutter_list_view_render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class FlutterListViewRender extends RenderSliver
var currentOffset = scrollOffset + compensationScroll;
var targetOffsetFromTop = elementOffset - currentOffset;
var distance = targetOffsetFromTop - _jumpDistanceFromTop;
if (distance != 0.0) {
if (distance < 0.0) {
Copy link
Owner

@robert-luoqing robert-luoqing May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is incorrect, The compensation distance may positive, because it may jump forward or backward

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change code like

if (_jumpToElement != null) {
      var elementOffset = _jumpToElement!.offset;
      var currentOffset = scrollOffset + compensationScroll;
      var targetOffsetFromTop = elementOffset - currentOffset;
      var distance = targetOffsetFromTop - _jumpDistanceFromTop;
      if (distance != 0.0) {
        compensationScroll += distance;
      }
      if (scrollOffset + compensationScroll < 0) {
        compensationScroll = -scrollOffset;
      } else if (childManager.totalItemHeight -
              scrollOffset -
              compensationScroll <
          viewportHeight) {
        compensationScroll =
            childManager.totalItemHeight - viewportHeight - scrollOffset;
        if (scrollOffset + compensationScroll < 0) {
          compensationScroll = 0;
        }
      } else if (scrollOffset + compensationScroll >
          childManager.totalItemHeight) {
        compensationScroll = childManager.totalItemHeight - scrollOffset;
      }
    }

compensationScroll += distance;
}
if (scrollOffset + compensationScroll < 0) {
Expand Down