FlutterEffectImpl.lazy constructor

FlutterEffectImpl.lazy(
  1. void fn(), {
  2. bool? detach,
  3. JoltDebugOption? debug,
})

Creates a new Flutter effect that does not run automatically upon creation.

This factory method is a convenience constructor for creating an effect with lazy set to true. The effect will not execute until you call run. After the first manual run, it will track dependencies and re-run at the end of frames whenever those dependencies change.

Parameters:

  • fn: The effect function to execute
  • detach: Whether to detach this effect from the current effect scope
  • debug: Optional debug options

Returns: A new FlutterEffect instance that starts in deferred mode

Example:

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

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

// Effect has not run yet
expect(values, isEmpty);

effect.run(); // Start tracking and run once
expect(values, equals([10]));

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

Implementation

factory FlutterEffectImpl.lazy(void Function() fn,
    {bool? detach, JoltDebugOption? debug}) {
  return FlutterEffectImpl(fn, lazy: true, detach: detach, debug: debug);
}