google / flutter.widgets

https://pub.dev/packages/flutter_widgets
BSD 3-Clause "New" or "Revised" License
1.37k stars 474 forks source link

scrollable_positioned_list: expose position, offset and add jumpToOffset in ScrollOffsetController #515

Closed yakagami closed 7 months ago

yakagami commented 7 months ago

Description

Exposes ScrollPosition and offset of the primary Scrollable within ScrollOffsetController. Also adds jumpToOffset which is the same as animateScroll but without animation (you cannot set Duration to zero so this is necessary). Exposing position allows us to use jumpToOffset as just jumpTo by subtracting the initial offset. Exposing ScrollPosition is useful for it's drag method which is similar to animateScroll but can be used with DragUpdateDetails from eg. onVerticalDragStart in a GestureDetector.

Fixes https://github.com/google/flutter.widgets/issues/513

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

yakagami commented 7 months ago

Looks like someone made a similar PR already here: https://github.com/google/flutter.widgets/pull/487. I think exposing position is also important as noted in the comments there.

yakagami commented 7 months ago

Looking into this further it seems jumpToOffset doesn't work for large offsets as explained here: https://github.com/google/flutter.widgets/issues/460#issuecomment-1522558856. It worked for my use case as well as in the test that I added here though