zema_forms 0.1.0
zema_forms: ^0.1.0 copied to clipboard
Flutter form widgets backed by Zema schemas. Surgical per-field rebuilds, isTouched UX, auto-focus on first error, and a form-level error banner.
Changelog #
All notable changes to this project will be documented in this file.
[Unreleased] #
0.1.0 #
Initial release.
Added #
-
ZemaFormController<T>— manages form state for aZemaObject-backed form.- Per-field
TextEditingControllerandValueNotifier<List<ZemaIssue>>for surgical rebuilds. isTouchedper-field state viatouchedFor(field)andmarkTouched(field). Errors are only visible after the field has lost focus orsubmit()has been called.isSubmitted: globalValueNotifier<bool>that reveals all errors at once on first submit.submitErrors:ValueNotifier<List<ZemaIssue>>holding all issues from the last failedsubmit(). Drives form-level error banners.FocusNoderegistry:registerFocusNode/unregisterFocusNode. On a failedsubmit(), focus moves automatically to the first field in error (schema declaration order). Hidden fields (canRequestFocus == false) are skipped silently; iteration stops at the canonical first error regardless.submit()— validates the full form, fans errors to per-field notifiers, auto-focuses first error field, returns typed outputTornull.validatorFor(field)— form-mode bridge returningString? Function(String?)for use withTextFormField.validator.setValue,hasErrors,reset,dispose.validateOnChangeflag (defaulttrue). Whenfalse, validation runs only onsubmit().initialValuesconstructor parameter for pre-populating fields.
- Per-field
-
ZemaTextField<T>—StatefulWidgetwrappingTextField.- Owns and manages a
FocusNode. Registers/unregisters with the controller automatically. - Calls
markTouched(field)on blur via focus listener. - Uses
ListenableBuilderoverListenable.merge([errorsFor, touchedFor, isSubmitted])for surgical rebuilds: only the field in error rebuilds. - Errors rendered via
InputDecoration.errorTextor a customerrorBuilder. - Resolves controller from explicit
controllerparameter or nearestZemaFormancestor.
- Owns and manages a
-
ZemaForm—InheritedWidgetscope providing aZemaFormControllerto descendants.updateShouldNotifyalways returnsfalse: zero rebuild overhead.ZemaForm.of<T>(context)for O(1) lookup.
-
Dispose order in
ZemaFormController.dispose()is intentional:TextEditingControllers first (removes write sources), per-field notifiers next, global notifiers (isSubmitted,submitErrors) last. Prevents orphaned listeners against already-disposed global state during fast screen teardown.