debugAssertNotDisposed static method Null safety

bool debugAssertNotDisposed(
  1. ChangeNotifier notifier
)

Used by subclasses to assert that the ChangeNotifier has not yet been disposed.

The debugAssertNotDisposed function should only be called inside of an assert, as in this example.
link
class MyNotifier with ChangeNotifier {
  void doUpdate() {
    assert(ChangeNotifier.debugAssertNotDisposed(this));
    // ...
  }
}

Implementation

// This is static and not an instance method because too many people try to
// implement ChangeNotifier instead of extending it (and so it is too breaking
// to add a method, especially for debug).
static bool debugAssertNotDisposed(ChangeNotifier notifier) {
  assert(() {
    if (notifier._debugDisposed) {
      throw FlutterError(
        'A ${notifier.runtimeType} was used after being disposed.\n'
        'Once you have called dispose() on a ${notifier.runtimeType}, it '
        'can no longer be used.',
      );
    }
    return true;
  }());
  return true;
}