hooks library
Optional flutter_hooks integration.
This is the only file in the package that imports
package:flutter_hooks/flutter_hooks.dart. If you don't need hooks you
can import only package:zard_flutter/zard_flutter.dart and use the
controller APIs directly.
Classes
Functions
-
useController<
T> (String name, {T? defaultValue, bool disabled = false, ZardFormController? form}) → ZardFieldController< T> -
Registers (or resolves) a ZardFieldController for
nameagainst the nearest ZardForm. Subscribes to the field's state so the calling hook widget rebuilds whenever the field's value/error/touched/etc. changes. -
useFieldArray<
E> (String name, {ZardFormController? form}) → ZardFieldArray< E> - Hook variant of ZardFormController.useFieldArray. Subscribes to the array's rows so reorders/insertions trigger a rebuild.
-
useFieldState<
T> (String name, {ZardFormController? form}) → ZardFieldState< T> -
Convenience: returns just the current ZardFieldState for
name. -
useForm(
{required ZMap schema, Map< String, dynamic> defaultValues = const {}, ValidationMode mode = ValidationMode.onSubmit, RevalidateMode revalidateMode = RevalidateMode.onChange, Duration debounce = Duration.zero, bool disabled = false, bool asyncValidation = false, bool excludeDisabledFromValues = false}) → ZardFormController -
React-Hook-Form-style
useFormhook. Creates a ZardFormController tied to the calling widget's lifecycle (disposed on unmount). Subscribes to the controller so form-level state flips (isSubmitting, isValid, etc.) cause a rebuild. -
useFormState(
{ZardFormController? form, List< Object?> listen(ZardFormSnapshot snapshot)?}) → ZardFormSnapshot -
Subscribes to form-level state. Pass
listento limit which fields of the snapshot trigger a rebuild — e.g.listen: (s) => [s.isSubmitting]. The returned tuple's equality drives rebuild decisions, so listing only what your UI uses keeps it cheap. -
useWatch<
T> (String name, {ZardFormController? form, T? defaultValue}) → T? - Reactive read of a single field's value. Subscribes only to that field's ValueListenable — other field changes do not trigger a rebuild here.
-
useZardFormContext(
) → ZardFormController -
Resolves the nearest ZardFormController from context. Throws if none is
found. Use inside a
HookWidgetdescendant of ZardForm.