scrollUntilVisible method Null safety

Future<void> scrollUntilVisible(
  1. Finder finder,
  2. double delta,
  3. {Finder? 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(
  Finder finder,
  double delta, {
    Finder? scrollable,
    int maxScrolls = 50,
    Duration duration = const Duration(milliseconds: 50),
) {
  assert(maxScrolls > 0);
  scrollable ??= 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,