useState<T> function

ValueNotifier<T> useState<T>(
  1. T initialData
)

A notifier of initialData, made by the first build and disposed with the element, whose changes rebuild it: count.value++ in a callback shows the new count. Later builds' initialData is ignored.

HookBuilder(
  builder: (context) {
    final count = useState(0);
    return KeyBindings({
      'up': () => count.value++,
    }, child: Text('Count: ${count.value}'));
  },
)

Implementation

ValueNotifier<T> useState<T>(T initialData) => use(_StateHook(initialData));