scrollTo method

Future<void> scrollTo(
  1. Finder finder, {
  2. Finder? scrollable,
  3. double delta = 100,
})

Scroll until a widget is visible in the nearest Scrollable.

Wraps Flutter's scrollUntilVisible with sensible defaults and graceful error handling.

Example:

await tester.scrollTo(find.text('Item 50'));
await tester.tapText('Item 50');

Implementation

Future<void> scrollTo(
  Finder finder, {
  Finder? scrollable,
  double delta = 100,
}) async {
  try {
    await scrollUntilVisible(
      finder,
      delta,
      scrollable: scrollable ?? find.byType(Scrollable).first,
    );
  } catch (e) {
    // Gracefully handle if already visible or scrollable not found
    await pump(const Duration(milliseconds: 100));
  }
  await settle();
}