pumpAndTrySettle method

Future<void> pumpAndTrySettle({
  1. Duration duration = const Duration(milliseconds: 100),
  2. EnginePhase phase = EnginePhase.sendSemanticsUpdate,
  3. Duration? timeout,
})

Calls WidgetTester.pumpAndSettle but doesn't throw if it times out. It prevents the test from failing when there's e.g. an infinite animation.

See also WidgetTester.pumpAndSettle.

Implementation

Future<void> pumpAndTrySettle({
  Duration duration = const Duration(milliseconds: 100),
  EnginePhase phase = EnginePhase.sendSemanticsUpdate,
  Duration? timeout,
}) async {
  try {
    await tester.pumpAndSettle(
      duration,
      phase,
      timeout ?? config.settleTimeout,
    );
    // We want to catch pumpAndSettle timeouts, so we can ignore them
    // ignore: avoid_catching_errors
  } on FlutterError catch (err) {
    if (err.message == 'pumpAndSettle timed out') {
      // This is fine. This method ignores pumpAndSettle timeouts on purpose
    } else {
      rethrow;
    }
  }
}