scrollUntilExists method

Future<PatrolFinder> scrollUntilExists({
  1. required Finder finder,
  2. Finder? view,
  3. double delta = defaultScrollDelta,
  4. AxisDirection? scrollDirection,
  5. int maxScrolls = defaultScrollMaxIteration,
  6. Duration? settleBetweenScrollsTimeout,
  7. Duration? dragDuration,
  8. SettlePolicy? settlePolicy,
})
inherited

Scrolls view in its scrolling direction until this finders finds at least one existing widget.

If view is null, it defaults to the first found Scrollable.

See also:

  • PatrolTester.scrollUntilVisible.

Implementation

Future<PatrolFinder> scrollUntilExists({
  required Finder finder,
  Finder? view,
  double delta = defaultScrollDelta,
  AxisDirection? scrollDirection,
  int maxScrolls = defaultScrollMaxIteration,
  Duration? settleBetweenScrollsTimeout,
  Duration? dragDuration,
  SettlePolicy? settlePolicy,
}) async {
  assert(maxScrolls > 0, 'maxScrolls must be positive number');
  view ??= find.byType(Scrollable);

  final scrollablePatrolFinder = await PatrolFinder(
    finder: view,
    tester: this,
  ).waitUntilVisible();
  AxisDirection direction;
  if (scrollDirection == null) {
    if (view.evaluate().first.widget is Scrollable) {
      direction = tester.firstWidget<Scrollable>(view).axisDirection;
    } else {
      direction = AxisDirection.down;
    }
  } else {
    direction = scrollDirection;
  }

  return TestAsyncUtils.guard<PatrolFinder>(() async {
    final moveStep = switch (direction) {
      AxisDirection.up => Offset(0, delta),
      AxisDirection.down => Offset(0, -delta),
      AxisDirection.left => Offset(delta, 0),
      AxisDirection.right => Offset(-delta, 0),
    };

    final resolvedFinder = await dragUntilExists(
      finder: finder,
      view: scrollablePatrolFinder.first,
      moveStep: moveStep,
      maxIteration: maxScrolls,
      settleBetweenScrollsTimeout: settleBetweenScrollsTimeout,
      dragDuration: dragDuration,
      settlePolicy: settlePolicy,
    );

    return resolvedFinder;
  });
}