quire-io / scroll-to-index

scroll to index with fixed/variable row height inside Flutter scrollable widget
MIT License
518 stars 105 forks source link

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

Open MiniSuperDev opened 2 years ago

MiniSuperDev commented 2 years ago

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

1203556555 commented 2 years ago

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

yunhe-lin commented 2 years ago

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

khomin commented 1 year ago

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

there is even no such code