addEffect method

void addEffect(
  1. void effectCb(), {
  2. String? debugLabel,
})

Registers a reactive effect that is automatically disposed when this controller is disposed.

The provided effectCb is invoked immediately and re-runs whenever any reactive signal read inside the callback emits a new value. If the controller is already disposed, this method is a no-op.

debugLabel optionally names the effect for debugging in devtools.

addEffect(() {
  if (isLoggedIn.value) {
    fetchDashboardData();
  }
}, debugLabel: 'auth-dashboard-trigger');

Implementation

void addEffect(void Function() effectCb, {String? debugLabel}) {
  if (_isDisposed) return;
  final dispose =
      effect(effectCb, debugLabel: debugLabel ?? '$runtimeType.effect');
  _disposers.add(dispose);
}