scroll-to-index icon indicating copy to clipboard operation
scroll-to-index copied to clipboard

It doesn't work when use a center key in CustomScrollView - Used for bidirectional list

Open MiniSuperDev opened this issue 2 years ago • 3 comments

Hi, I try to create a bidirectional lazy load list like the like flutter docs said https://github.com/flutter/flutter/blob/5464c5bac742001448fe4fc0597be939379f88ea/packages/flutter/lib/src/widgets/scroll_view.dart#L502-L513

I create a gist where you can enable a disable the center key, and you can see that only highlight work, but the scrollTo not work when the center key is enable.

how can I keep the scroll to index behavior while have the center key? or maybe do you know other way to create a list that append items to the top of the list by preserving the scroll, the solution that I used is from https://github.com/flutter/flutter/issues/21541#issuecomment-629121578

thank you

MiniSuperDev avatar May 12 '22 03:05 MiniSuperDev

I also encountered this problem. Have you found any solutions? @MiniSuperDev

1203556555 avatar Jul 04 '22 07:07 1203556555

AutoScrollControllerMixin:

while (prevOffset != currentOffset && !(contains = isIndexStateInLayoutRange(index))) { prevOffset = currentOffset; final nearest = _getNearestIndex(index); final moveTarget = _forecastMoveUnit(index, nearest, usedSuggestedRowHeightIfAny)!; if (moveTarget < 0) //can't forecast the move range return null; // assume suggestRowHeight will move to correct offset in just one time. // if the rule doesn't work (in variable row height case), we will use backup solution (non-suggested way) final suggestedDuration = usedSuggestedRowHeightIfAny && suggestedRowHeight != null ? duration : null;

remove if (moveTarget < 0) //can't forecast the move range return null; is useful

yunhe-lin avatar Aug 09 '22 05:08 yunhe-lin