useValueNotifier<T> function

ValueNotifier<T> useValueNotifier<T>(
  1. T initialData, [
  2. List<Object?>? keys
])

A notifier of initialData, made by the first build, made anew when the keys of a build differ from the last one's, and disposed with the element or when replaced. Unlike useState's, its changes rebuild nothing: useListenable or a ValueListenableBuilder listen to it.

A notifier that only the widgets listening to it rebuild for:

HookBuilder(
  builder: (context) {
    final progress = useValueNotifier(0.0);
    return ValueListenableBuilder(
      valueListenable: progress,
      builder: (context, value, _) => Text('${(value * 100).round()} %'),
    );
  },
)

Implementation

ValueNotifier<T> useValueNotifier<T>(T initialData, [List<Object?>? keys]) =>
    use(_ValueNotifierHook(initialData, keys));