isOrWillBeDisposed property

  1. @override
bool isOrWillBeDisposed
inherited

Whether the disposal of this object has been requested, is in progress, or is complete.

This will become true as soon as the dispose method is called and will remain true forever.

Recommended usage of this boolean is to guard public APIs such that all calls after disposal has been requested (via dispose) are rejected:

Response sendRequest() async {
  if (isOrWillBeDisposed) {
    throw new StateError(
        'sendRequest() cannot be called, object is disposing');
  }
  ...
}

Implementation

@override
bool get isOrWillBeDisposed => _disposable.isOrWillBeDisposed;