scrollUntilVisible method

Future<void> scrollUntilVisible(
  1. FinderBase<Element> finder,
  2. double delta,
  3. {FinderBase<Element>? scrollable,
  4. int maxScrolls = 50,
  5. Duration duration = const Duration(milliseconds: 50)}

Repeatedly scrolls a Scrollable by delta in the Scrollable.axisDirection direction until a widget matching finder is visible.

Between each scroll, advances the clock by duration time.

Scrolling is performed until the start of the finder is visible. This is due to the default parameter values of the Scrollable.ensureVisible method.

If scrollable is null, a Finder that looks for a Scrollable is used instead.

Throws a StateError if finder is not found after maxScrolls scrolls.

This is different from ensureVisible in that this allows looking for finder that is not yet built. The caller must specify the scrollable that will build child specified by finder when there are multiple Scrollables.

See also:


Future<void> scrollUntilVisible(
  finders.FinderBase<Element> finder,
  double delta, {
    finders.FinderBase<Element>? scrollable,
    int maxScrolls = 50,
    Duration duration = const Duration(milliseconds: 50),
) {
  assert(maxScrolls > 0);
  scrollable ??= finders.find.byType(Scrollable);
  return TestAsyncUtils.guard<void>(() async {
    Offset moveStep;
    switch (widget<Scrollable>(scrollable!).axisDirection) {
      case AxisDirection.up:
        moveStep = Offset(0, delta);
      case AxisDirection.down:
        moveStep = Offset(0, -delta);
      case AxisDirection.left:
        moveStep = Offset(delta, 0);
      case AxisDirection.right:
        moveStep = Offset(-delta, 0);
    await dragUntilVisible(
      maxIteration: maxScrolls,
      duration: duration,