scrollUntilVisible method
Future<PatrolFinder>
scrollUntilVisible({
- required Finder finder,
- Finder? view,
- double delta = defaultScrollDelta,
- AxisDirection? scrollDirection,
- int maxScrolls = defaultScrollMaxIteration,
- Duration? settleBetweenScrollsTimeout,
- Duration? dragDuration,
- SettlePolicy? settlePolicy,
Scrolls view
in scrollDirection
until this finders finds
at least one existing widget.
If view
is null, it defaults to the first found Scrollable.
This is a reimplementation of WidgetController.scrollUntilVisible that
doesn't throw when finder
finds more than one widget.
See also:
Implementation
Future<PatrolFinder> scrollUntilVisible({
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 {
Offset moveStep;
switch (direction) {
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);
}
final resolvedFinder = await dragUntilVisible(
finder: finder,
view: scrollablePatrolFinder.first,
moveStep: moveStep,
maxIteration: maxScrolls,
settleBetweenScrollsTimeout: settleBetweenScrollsTimeout,
dragDuration: dragDuration,
settlePolicy: settlePolicy,
);
return resolvedFinder;
});
}