waitUntilVisible method
Future<Finder>
waitUntilVisible(
- Finder finder, {
- Duration? timeout,
- Alignment alignment = Alignment.center,
- Duration? settleDuration,
override
Implementation
@override
Future<Finder> waitUntilVisible(
Finder finder, {
Duration? timeout,
Alignment alignment = Alignment.center,
Duration? settleDuration,
}) async {
final effectiveTimeout = timeout ?? config.visibleTimeout;
final live = isLiveBinding;
debugPrint('⏳ [NativeAction] Waiting for widget to become visible: $finder '
'(timeout: $effectiveTimeout, liveBinding: $live)');
final stopwatch = Stopwatch()..start();
while (stopwatch.elapsed < effectiveTimeout) {
// Drain stray async exceptions early so they don't silently corrupt
// test state (critical for PreviewTestBinding).
drainAndRethrowException(_tester);
if (finder.evaluate().isNotEmpty && finder.hitTestable().evaluate().isNotEmpty) {
debugPrint('✅ [NativeAction] Widget became visible after '
'${stopwatch.elapsed}: $finder');
if (settleDuration != null) {
debugPrint('⏳ [NativeAction] Settling for $settleDuration...');
await pumpForDuration(_tester, duration: settleDuration);
}
return finder;
}
// Pump in a binding-aware way:
// - AutomatedTestWidgetsFlutterBinding: pump(100ms) advances the fake clock
// - Live/Preview bindings: pump() renders immediately, real async progresses
await bindingAwarePump(_tester);
}
throw Exception('Timeout waiting for widget to become visible: $finder '
'after ${stopwatch.elapsed}');
}