Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,15 @@ class ItemScrollController {
/// This is an experimental API and is subject to change.
/// Behavior may be ill-defined in some cases. Please file bugs.
class ScrollOffsetController {
/// ScrollPosition of the current ScrollablePositionedList. Values such as
/// pixels, maxScrollExtent and jumpTo are not necessarily defined to start
/// from the beginning of the list. When itemScrollController.jumpTo is
/// called, the list will begin from that index. unstableScrollPosition.jumpTo
/// will cause the application to freeze at very large values as it must build
/// all the widgets between the starting offset and the ending offset.
ScrollPosition get unstableScrollPosition =>
_scrollableListState!.primary.scrollController.position;

Future<void> animateScroll(
{required double offset,
required Duration duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,30 @@ void main() {

await tester.pumpAndSettle();
});

testWidgets('Programtically jump down 50 pixels',
(WidgetTester tester) async {
final scrollDistance = 50.0;

ScrollOffsetController scrollOffsetController = ScrollOffsetController();

await setUpWidgetTest(
tester,
scrollOffsetController: scrollOffsetController,
initialIndex: 5,
);

final originalOffset = tester.getTopLeft(find.text('Item 5')).dy;

final currentPosition =
scrollOffsetController.unstableScrollPosition.pixels;
final newPosition = currentPosition - scrollDistance;

scrollOffsetController.unstableScrollPosition.jumpTo(newPosition);
await tester.pumpAndSettle();

final newOffset = tester.getTopLeft(find.text('Item 5')).dy;

expect(newOffset - originalOffset, scrollDistance);
});
}