maybeDispatchObjectCreation static method

  1. @protected
void maybeDispatchObjectCreation(
  1. ChangeNotifier object
)

Dispatches the event of the object creation to Listenable.debugMaybeDispatchCreated.

Tools like leak_tracker use the event of object creation to help developers identify the owner of the object, for troubleshooting purposes, by taking stack trace at the moment of the event.

But, as ChangeNotifier is mixin, it does not have its own constructor. So, it communicates object creation in first addListener, that results in the stack trace pointing to addListener, not to constructor.

To make debugging easier, invoke ChangeNotifier.maybeDispatchObjectCreation in constructor of the class. It will help to identify the owner.

Implementation

@protected
static void maybeDispatchObjectCreation(ChangeNotifier object) {
  assert(() {
    if (!object._debugCreationDispatched) {
      Listenable.debugMaybeDispatchCreated('ChangeNotifier', object);
      object._debugCreationDispatched = true;
    }
    return true;
  }());
}