dispose method
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:
- The frame callback that was requested by scheduleTick, if any, is canceled.
- The future that was returned by start does not resolve.
- The future obtained from TickerFuture.orCancel, if any, resolves with a TickerCanceled error.
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;
}());
}