dispose method

  1. @mustCallSuper
void dispose()

Release the resources used by this object. The object is no longer usable after this method is called.

It is legal to call this method while isActive is true, in which case:

Implementation

@mustCallSuper
void dispose() {
  // TODO(polina-c): stop duplicating code across disposables
  // https://github.com/flutter/flutter/issues/137435
  if (kFlutterMemoryAllocationsEnabled) {
    FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
  }

  if (_future != null) {
    final TickerFuture localFuture = _future!;
    _future = null;
    assert(!isActive);
    unscheduleTick();
    localFuture._cancel(this);
  }
  assert(() {
    // We intentionally don't null out _startTime. This means that if start()
    // was ever called, the object is now in a bogus state. This weakly helps
    // catch cases of use-after-dispose.
    _startTime = Duration.zero;
    return true;
  }());
}