addTime method Null safety

  1. @override
void addTime(
  1. Duration duration

Increase the timeout for the current test by the given duration.

This only matters if the test has an initialTimeout set on testWidgets, and the test is running via flutter test. By default, tests do not have such a timeout. Tests run using flutter run never time out even if one is specified.

This method has no effect on the timeout specified via timeout on testWidgets. That timeout is implemented by the test package.

By default, each pump and WidgetTester.pumpWidget call increases the timeout by a hundred milliseconds, and each matchesGoldenFile expectation increases it by a minute. If there is no timeout in the first place, this has no effect.

The granularity of timeouts is coarse: the time is checked once per second, and only when the test is not executing. It is therefore possible for a timeout to be exceeded by hundreds of milliseconds and for the test to still succeed. If precise timing is required, it should be implemented as a part of the test rather than relying on this mechanism.

See also:

  • testWidgets, on which a timeout can be set using the timeout argument.
  • defaultTestTimeout, the maximum that the timeout can reach. (That timeout is implemented by the test package.)


void addTime(Duration duration) {
  if (_timeout != null)
    _timeout = _timeout! + duration;