dragUntilVisible method
- required Finder finder,
- required Finder view,
- required Offset moveStep,
- int maxIteration = defaultScrollMaxIteration,
- Duration? settleBetweenScrollsTimeout,
- Duration? dragDuration,
- SettlePolicy? settlePolicy,
- Alignment alignment = Alignment.center,
- bool enablePatrolLog = true,
Repeatedly drags view by moveStep until finder finds at least one
visible widget.
Between each drag, calls pump, pumpAndSettle or pumpAndTrySettle,
depending on chosen settlePolicy.
This is a reimplementation of WidgetController.dragUntilVisible that differs from the original in the following ways:
-
waits until
viewis visible -
if the
viewfinder finds more than 1 widget, it scrolls the first one instead of throwing a StateError -
if the
finderfinder finds more than 1 widget, it scrolls to the first one instead of throwing a StateError -
can drag any widget, not only a Scrollable
-
performed drag is slower (it takes some time to perform dragging gesture, half a second by default)
-
you can configure, which version of pumping is performed between each drag gesture (
pump,pumpAndSettleorpumpAndTrySettle) -
timeouts and durations, if null, are controlled by values in
PatrolTester.config.
See also:
PatrolTester.dragUntilExists, which scrolls to existing widget, not a visible one.
Implementation
Future<PatrolFinder> dragUntilVisible({
required Finder finder,
required Finder view,
required Offset moveStep,
int maxIteration = defaultScrollMaxIteration,
Duration? settleBetweenScrollsTimeout,
Duration? dragDuration,
SettlePolicy? settlePolicy,
Alignment alignment = Alignment.center,
bool enablePatrolLog = true,
}) {
return TestAsyncUtils.guard(
() => wrapWithPatrolLog<PatrolFinder>(
action: 'dragUntilVisible',
finder: view,
color: AnsiCodes.blue,
enablePatrolLog: enablePatrolLog,
function: () async {
final viewPatrolFinder = (await waitUntilVisible(
PatrolFinder(finder: view, tester: this),
enablePatrolLog: false,
)).first;
dragDuration ??= config.dragDuration;
settleBetweenScrollsTimeout ??= config.settleBetweenScrollsTimeout;
final hitTestableFinder = finder.hitTestable(at: alignment);
var iterationsLeft = maxIteration;
while (iterationsLeft > 0 && hitTestableFinder.evaluate().isEmpty) {
await tester.timedDrag(viewPatrolFinder, moveStep, dragDuration!);
await _performPump(
settlePolicy: settlePolicy,
settleTimeout: settleBetweenScrollsTimeout,
);
iterationsLeft -= 1;
}
if (iterationsLeft <= 0) {
throw WaitUntilVisibleTimeoutException(
finder: hitTestableFinder,
// TODO: set reasonable duration or create new exception for this case
duration: settleBetweenScrollsTimeout!,
);
}
return PatrolFinder(finder: hitTestableFinder.first, tester: this);
},
),
);
}