FlutterEffectImpl constructor
FlutterEffectImpl(
- void fn(), {
- bool lazy = false,
- bool? detach,
- JoltDebugOption? debug,
Creates a new Flutter effect with the given function.
Parameters:
fn: The effect function to executelazy: Whether to defer running the effect on creation. Iftrue, the effect will NOT run immediately and will not track dependencies until you call run. Iffalse(default), the effect runs immediately on creation and then re-runs at frame end whenever its reactive dependencies change.detach: Whether to detach this effect from the current effect scope. If true, the effect will not be automatically disposed when its parent scope is disposed.debug: Optional debug options
The effect function will be called at the end of the current Flutter frame, batching multiple triggers within the same frame into a single execution.
Example:
final signal = Signal(0);
// Effect runs at end of frame when signal changes
final effect = FlutterEffect(() {
print('Signal value: ${signal.value}');
});
signal.value = 1;
signal.value = 2;
// Effect executes once at end of frame with signal.value = 2
Implementation
FlutterEffectImpl(this.fn, {bool lazy = false, bool? detach, JoltDebugOption? debug})
: super(flags: ReactiveFlags.watching | ReactiveFlags.recursedCheck) {
JoltDebug.create(this, debug);
if (!(detach ?? false)) {
final prevSub = getActiveSub();
if (prevSub != null) {
link(this, prevSub, 0);
}
}
if (!lazy) {
final prevSub = setActiveSub(this);
try {
_effectFn();
} finally {
setActiveSub(prevSub);
flags &= ~ReactiveFlags.recursedCheck;
}
} else {
flags &= ~ReactiveFlags.recursedCheck;
}
}