wait method

Future<Finder> wait({
  1. String? scrollableId,
  2. required int timeoutMs,
})

Implementation

Future<Finder> wait({
  String? scrollableId,
  required int timeoutMs,
}) async {
  final scrollables = scrollableId == null || scrollableId.isEmpty
      ? find.byType(Scrollable)
      : find.descendant(
          of: find.byKey(ValueKey(scrollableId)),
          matching: find.byType(Scrollable),
        );
  final stopwatch = Stopwatch()..start();
  while (scrollables.evaluate().isEmpty &&
      stopwatch.elapsedMilliseconds < timeoutMs) {
    final remainingMs = timeoutMs - stopwatch.elapsedMilliseconds;
    final pollMs = config.waitPollInterval.inMilliseconds;
    await tester.pump(Duration(
      milliseconds: remainingMs < pollMs ? remainingMs : pollMs,
    ));
  }
  if (scrollables.evaluate().isEmpty) {
    throw EnsembleTestFailure(
      'Timed out after ${timeoutMs}ms waiting for a scrollable to appear',
    );
  }
  return scrollableId == null || scrollableId.isEmpty
      ? find.byType(Scrollable).first
      : scrollables;
}