createEffect method

EffectCleanup createEffect(
  1. dynamic cb(), {
  2. String? debugLabel,
  3. dynamic onDispose()?,
})

Create a effect.

Do not call inside the build method.

Calling this method in build() will create a new effect every render.

Implementation

EffectCleanup createEffect(
  dynamic Function() cb, {
  String? debugLabel,
  dynamic Function()? onDispose,
}) {
  final s = effect(
    cb,
    debugLabel: debugLabel,
    onDispose: onDispose,
  );
  _effects.add(s);
  return () {
    _effects.remove(s);
    s();
  };
}