scrollUntilVisible method
- FinderBase<
Element> finder, - double delta, {
- FinderBase<
Element> ? scrollable, - int maxScrolls = 50,
- Duration duration = const Duration(milliseconds: 50),
- bool continuous = false,
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.
If continuous is true, the gesture will be reused to simulate the effect
of actual finger scrolling, which is useful when used alongside listeners
like GestureDetector.onTap. The default is false.
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:
- dragUntilVisible, which implements the body of this method.
Implementation
Future<void> scrollUntilVisible(
finders.FinderBase<Element> finder,
double delta, {
finders.FinderBase<Element>? scrollable,
int maxScrolls = 50,
Duration duration = const Duration(milliseconds: 50),
bool continuous = false,
}) {
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(
finder,
scrollable,
moveStep,
maxIteration: maxScrolls,
duration: duration,
continuous: continuous,
);
});
}