diff --git a/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart b/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart index 6e270f6d..4b10f3d1 100644 --- a/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart +++ b/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart @@ -180,9 +180,15 @@ class ScrollablePositionedList extends StatefulWidget { class ItemScrollController { /// Whether any ScrollablePositionedList objects are attached this object. /// - /// If `false`, then [jumpTo] and [scrollTo] must not be called. + /// If `false`, then [jumpTo], [scrollTo] and [jumpToPixel] must not be called. bool get isAttached => _scrollableListState != null; + /// Returns the current [scrollController.offset]. + /// Also see [jumpToPixel]. + double get currentScrollControllerOffset { + return _scrollableListState!.primary.scrollController.offset; + } + _ScrollablePositionedListState? _scrollableListState; /// Immediately, without animation, reconfigure the list so that the item at @@ -245,6 +251,23 @@ class ItemScrollController { ); } + /// Immediately jump the list to the provided [value] via [scrollController.jumpTo]. + /// Also see [currentScrollControllerOffset]. + void jumpToPixel(double value) { + _scrollableListState!.primary.scrollController.jumpTo(value); + } + + /// Calls [primary.scrollController.animateTo] with the given values. + /// See [currentScrollControllerOffset] to get the current offset. + void scrollToPixel({ + required double offset, + required Duration duration, + required Curve curve, + }) { + _scrollableListState!.primary.scrollController + .animateTo(offset, duration: duration, curve: curve); + } + void _attach(_ScrollablePositionedListState scrollableListState) { assert(_scrollableListState == null); _scrollableListState = scrollableListState;