FlutterEffectImpl.lazy constructor

FlutterEffectImpl.lazy(
  1. void fn(), {
  2. JoltDebugFn? onDebug,
})

Creates a new Flutter effect that runs immediately upon creation.

This factory method is a convenience constructor for creating an effect with lazy set to true. The effect will execute once immediately when created, then automatically re-run at the end of frames whenever its reactive dependencies change.

Parameters:

  • fn: The effect function to execute
  • onDebug: Optional debug callback for reactive system debugging

Returns: A new FlutterEffect instance that executes immediately

Example:

final signal = Signal(10);
final values = <int>[];

FlutterEffect.lazy(() {
  values.add(signal.value);
});

// Effect executed immediately with value 10
expect(values, equals([10]));

signal.value = 20; // Effect schedules for end of frame

Implementation

factory FlutterEffectImpl.lazy(void Function() fn, {JoltDebugFn? onDebug}) {
  return FlutterEffectImpl(fn, lazy: true, onDebug: onDebug);
}