call method

  1. @defineHook
FlutterEffect call(
  1. void effect(), {
  2. bool lazy = false,
  3. JoltDebugOption? debug,
})

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 execute
  • lazy: Whether to defer running the effect on creation. If true, the effect will NOT run immediately and will not track dependencies until you call run on the returned effect. If false (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));
}