flutter_hook_form 4.0.0
flutter_hook_form: ^4.0.0 copied to clipboard
A Flutter package that provides a hook to manage form fields.
4.0.0 #
Breaking Changes #
-
💥 New
FieldSchemainterface: Form schemas now use anenumimplementing theFieldSchema<T>interface instead of a class withstatic final HookFielddeclarations.// Before (3.x) class MyFormSchema extends FormSchema { static final email = HookField<String>(validators: [RequiredValidator()]); } // After (4.0) enum MyFormSchema<T> implements FieldSchema<T> { email<String>(validators: [RequiredValidator(), EmailValidator()]); const MyFormSchema({this.validators}); @override final List<Validator<T>>? validators; } -
💥
useFormContextno longer accepts a type parameter: Drop the generic argument at all call sites.// Before final form = useFormContext<SignInFormFields>(context); // After final form = useFormContext(context); -
💥
HookedFormFieldtype parameters updated: Now requires<F extends FieldSchema, T>for improved type inference. -
💥
getNotifierreturn type narrowed toValueListenable<T?>: The value is now read-only from outside the controller; useupdateValueto change it. -
💥 Dart SDK requirement upgraded: Minimum Dart SDK version is now
^3.10.4.
New Features #
-
✨
form.listenextension for reactive field listening: Subscribe to one or more fields and derive state — the widget rebuilds only when the watched fields change.// Single field final email = form.listen({Fields.email}, (get) => get<String>(Fields.email)); // Derived state across multiple fields final canSubmit = form.listen( {Fields.email, Fields.password}, (get) => get<String>(Fields.email) != null && get<String>(Fields.password) != null, ); -
✨ Cross-field validation: New
CrossFieldValidator<T>base class plus built-inMatchesValidator<T>andDateAfterValidator. -
✨ New example project: Comprehensive example demonstrating schemas, validation, and cross-field validation.
Improvements #
- ♻️ Unified per-field notifier architecture:
FormFieldsControllernow uses a single_FieldNotifierper field, eliminating double-notify bugs. - ♻️ Simplified
getValue: Reads exclusively from the field's notifier, seeded frominitialValues. - ♻️
updateValue(notify: false)writes silently viasetSilently— value is always stored even when listeners are suppressed. - ♻️
resettriggers a single notification per field.
Deprecated #
- ⚠️
useFieldValue: Useform.listen({field}, (get) => get<T>(field))instead.
4.0.0-rc.3 #
Breaking Changes #
-
💥
useFormContextno longer accepts a type parameter: The hook is now untyped for simplicity. Update call sites by dropping the generic argument.Before (rc.2):
final form = useFormContext<SignInFormFields>(context);After (rc.3):
final form = useFormContext(context); -
💥
getNotifierreturn type narrowed toValueListenable<T?>: Previously returnedValueNotifier<T?>, which allowed external mutation. The value is now read-only from outside the controller; useupdateValueto change it.
Improvements #
- ♻️ Unified per-field notifier architecture:
FormFieldsControllernow uses a single_FieldNotifierper field (instead of two separate maps — one typed, one untyped). This eliminates a class of double-notify bugs and makesform.listen,getNotifier, andupdateValueall share the same reactive source of truth. - ♻️ Simplified
getValue: No longer reads widget state as a side channel — the canonical value is always the field's notifier, seeded frominitialValues. - ♻️
updateValue(notify: false)writes silently: UsessetSilentlyinstead of skipping the notifier entirely, so the value is always stored even when listeners are suppressed. - ♻️
resettriggers a single notification per field: Reset no longer requires a separate loop over change-notifiers.
4.0.0-rc.1 #
Breaking Changes #
-
💥 New
FieldSchemainterface: Form schemas now use anenumimplementing theFieldSchemainterface instead of a class withstatic final HookFielddeclarations. This reduces boilerplate and improves type safety.Before (3.x):
class MyFormSchema extends FormSchema { static final email = HookField<String>(validators: [RequiredValidator()]); static final password = HookField<String>(validators: [MinLengthValidator(8)]); @override List<HookField> get fields => [email, password]; }After (4.x):
enum MyFormSchema<T> implements FieldSchema<T> { email<String>(validators: [RequiredValidator(), EmailValidator()]), password<String>(validators: [RequiredValidator(), MinLengthValidator(8)]); const MyFormSchema({this.validators}); @override final List<Validator<T>>? validators; } -
💥
HookedFormFieldtype parameters updated: Now requires<F extends FieldSchema, T>for improved type inference across form field widgets. -
💥 Dart SDK requirement upgraded: Minimum Dart SDK version is now
^3.10.4.
New Features #
-
✨ Cross-field validation support: New
CrossFieldValidator<T>base class enables validation that depends on other field values in the form. -
✨ New cross-field validators:
MatchesValidator<T>- Validates that a field value matches another field (e.g., password confirmation)DateAfterValidator- Validates that a date field is after another date field
-
✨ New example project: Added a comprehensive example project demonstrating form schemas, validation, and cross-field validation.
3.0.1 #
- 📝: Update README.md to include instructions for creating a schema and overriding fields in FormSchema
3.0.0 #
Breaking changes #
- 💥 FormSchema generator has been removed as the generated code did not justify keeping the generator. Indeed, the only perk of the generator was to avoid having to write by hand the id of each hook field.
Migration guide: Simply expose the generated form schema and remove the file that was used for generation.
2.0.6 #
- 🔧 Upgrade dart SDK to ^3.8.0
2.0.2 #
Improvements #
- ♻️ Update initialization business logic to avoid loosing initial value state on rebuild.
2.0.0 #
Breaking changes #
- 💥
FormProviderhas been renamed toHookedFormProvider - 💥
FormFieldSchemeandHookedFieldIdhave been merged intoHookField - 💥
FormSchemanow declare afieldsproperty to setup form fiels instead of usingsuperconstructor - 💥
buildersyntax has changed onHookedFormFieldallowing to declare anonymous parameters.
Improvements #
- 🐛 Fix
PatternValidatorfor failing on empty strings. Now fails only on non-empty values.
New Features #
- ✨
FormControllercan now be initialized- Generated
FormSchemadeclare a static to initialized eachHookField withInitialValuemethod has been added toHookFieldto initialized a hook field with a given value.
- Generated
1.1.1 #
Improvements #
- ✨ Enhanced
FormFieldsControllerwith improved validation and error handling:- Added optional
notifyandclearErrorsparameters tovalidate()method for more control - Added
setError()method withnotifyparameter to control rebuilds - Introduced
clearForcedErrors()method to manage form errors independently - Added new state tracking properties:
hasBeenInteracted- Detects if any field has been interacted with by userhasChanged- Checks if any field value differs from its initial value
- Added optional
Fix #
- 🐛 Update form generator to correctly identify closing brackets for generic types in annotations.
1.1.0 #
New Features #
-
✨ Introduced
HookedFieldId<F, T>with generic type parameters for improved type safety:- The form schema type
Fis now included in the field ID - This enables better type inference when using form fields
- No need to specify form schema type in most widget usages
- The form schema type
-
🔄 Added reactive form capabilities:
- Form controller now properly notifies listeners when field values change
- Added
registerFieldChangemethod to track field modifications - Added methods to check if fields are dirty:
isDirty,areAnyDirty,areAllDirty
-
✨ Introduced
HookedFormFieldandHookedTextFormField:- Updated to use the new
fieldHookparameter instead offieldKey - Better type inference from field hooks
- Added support for tracking field changes
- Updated to use the new
Improvements #
-
📝 Comprehensive documentation updates:
- Added examples for custom form fields
- Improved explanation of form initialization
- Added section on writing custom form fields
- Updated code examples to use the latest API
-
🐛 Fixed validation issues:
- Resolved bug where forced errors took precedence over validation errors
- Improved error clearing during validation
- Better handling of field rebuilds after validation
Breaking Changes #
- 🔄 Renamed parameter from
fieldKeytofieldHookin form field widgets- Update your code to use
fieldHook: MySchema.fieldinstead offieldKey: MySchema.field - This change better reflects the purpose of the parameter
- Update your code to use
1.0.0 #
Breaking Changes #
-
⚠️ Validator usage has been updated to support internationalization:
- Validators are now declared in a list instead of being chained in a function.
- Validators now return
errorCodeinstead of error messages - Error messages are handled through the
FormErrorMessagesclass - Custom validators need to extend
Validator<T>and provide anerrorCode - See the documentation for migration details
-
✨ Add code generation support for form schemas
-
🌍 Add built-in internationalization support
-
🛠️ Improve code organization and maintainability
0.0.4 #
- Add comprehensive documentation
- Update exports
- Add example for package demonstration
0.0.3 #
- Downgrade mime package to 1.0.6
0.0.2 #
- Add test suite and improve comments
0.0.1 #
- Init project