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

fix initIndex issue #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Marco-Ryus
Copy link

#30

@@ -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;
      }
    }

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

Successfully merging this pull request may close these issues.

2 participants