addListener method

  1. @Deprecated('Do not use this method directly. Use [addStrongRefListener] instead')
  2. @protected
  3. @override
void addListener(
  1. VoidCallback listener
)
override

❌ Do not use this method directly. Use addStrongRefListener instead.

Implementation

@Deprecated(
  'Do not use this method directly. Use [addStrongRefListener] instead',
)
@protected
@override
void addListener(VoidCallback listener) {
  _garbageCollect();
  _maybeReallocate();
  _listeners[_count++] = WeakReference(listener);
  if (printGarbageCollectionStatus && kDebugMode) {
    _debugFinalizers ??= [];
    (_debugFinalizers ??= [])
      ..add(
        Finalizer<VoidCallback>(
          (target) {
            if (kDebugMode) {
              print(
                '[$WeakChangeNotifier] A listener of type "$runtimeType" has been garbage collected.',
              );
            }
          },
        ),
      )
      ..last.attach(listener, () {});
  }
}