call method
Creates a Flutter effect hook that schedules execution at frame end.
Flutter effects run automatically when their reactive dependencies change,
but execution is scheduled at the end of the current Flutter frame. This
batches multiple triggers within the same frame into a single execution,
which is useful for UI-related side effects that should not interfere
with frame rendering. Use onEffectCleanup inside the effect to register
cleanup functions.
Parameters:
effect: 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 callrunon the returned effect. Iffalse(default), the effect runs immediately on creation and then re-runs at frame end whenever its reactive dependencies change.debug: Optional debug options
Returns: A FlutterEffect that tracks dependencies and runs at frame end
Example:
setup(context, props) {
final count = useSignal(0);
useFlutterEffect(() {
print('Count changed: ${count.value}'); // Executes at frame end
final timer = Timer.periodic(Duration(seconds: 1), (_) {
count.value++;
});
onEffectCleanup(() => timer.cancel());
});
return () => Text('Count: ${count.value}');
}
Implementation
@defineHook
FlutterEffect call(void Function() effect,
{bool lazy = false, JoltDebugOption? debug}) {
return useHook(_UseFlutterEffectHook(effect, lazy, debug));
}