addListener method
- @Deprecated('Do not use this method directly. Use [addStrongRefListener] instead')
- @protected
- @override
- 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, () {});
}
}