Flutter: how to test the scroll Flutter: how to test the scroll flutter flutter

Flutter: how to test the scroll


You can create a TestGesture in your tests and perform a scroll that way.

final gesture = await tester.startGesture(Offset(0, 300)); //Position of the scrollviewawait gesture.moveBy(Offset(0, -300)); //How much to scroll byawait tester.pump();


If you pass the key parameter to the builder:

ListView.builder(key: Key('ListViewKey'),...);

Then finding by key:

await tester.drag(find.byKey(Key('ListViewKey')), const Offset(0.0, -300));await tester.pump();

Will work.


for those using the new flutter_test lib, we also have the dragUntilVisible method:

await tester.dragUntilVisible(    find.text('Earn mana!'), // what you want to find    find.byKey(ValueKey('OnboardingCarousel')), // widget you want to scroll    const Offset(-250, 0), // delta to move);