verifyTickersWereDisposed method

void verifyTickersWereDisposed([
  1. String when = 'when none should have been'
])

Throws an exception if any tickers created by the WidgetTester are still active when the method is called.

An argument can be specified to provide a string that will be used in the error message. It should be an adverbial phrase describing the current situation, such as "at the end of the test".

Implementation

void verifyTickersWereDisposed([ String when = 'when none should have been' ]) {
  if (_tickers != null) {
    for (final Ticker ticker in _tickers!) {
      if (ticker.isActive) {
        throw FlutterError.fromParts(<DiagnosticsNode>[
          ErrorSummary('A Ticker was active $when.'),
          ErrorDescription('All Tickers must be disposed.'),
          ErrorHint(
            'Tickers used by AnimationControllers '
            'should be disposed by calling dispose() on the AnimationController itself. '
            'Otherwise, the ticker will leak.'
          ),
          ticker.describeForError('The offending ticker was'),
        ]);
      }
    }
  }
}