writable<T> method
WritableComputed<T>
writable<T>(})
Creates a writable computed signal hook with custom getter and setter.
A writable computed signal allows you to define custom read and write behavior, enabling two-way data binding with derived values.
Parameters:
getter: Function that computes the current valuesetter: Function that handles value updateskeys: Optional keys for hook memoizationdebug: Optional debug options
Returns: A WritableComputed with custom read/write behavior
Example:
Widget build(BuildContext context) {
final count = useSignal(0);
final doubled = useComputed.writable(
() => count.value * 2,
(value) => count.value = value ~/ 2,
);
return Column(
children: [
Text('Count: ${count.value}'),
Text('Doubled: ${doubled.value}'),
ElevatedButton(
onPressed: () => doubled.value = 10,
child: Text('Set doubled to 10'),
),
],
);
}
Implementation
WritableComputed<T> writable<T>(
T Function() getter,
void Function(T) setter, {
List<Object?>? keys,
JoltDebugOption? debug,
}) {
return use(
JoltHook(() => WritableComputed(getter, setter, debug: debug),
keys: keys),
);
}