scrollUntilExists method
Future<PatrolFinder>
scrollUntilExists({
- required Finder finder,
- Finder? view,
- double delta = defaultScrollDelta,
- AxisDirection? scrollDirection,
- int maxScrolls = defaultScrollMaxIteration,
- Duration? settleBetweenScrollsTimeout,
- Duration? dragDuration,
- 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;
});
}