fabrik_forms 0.2.0
fabrik_forms: ^0.2.0 copied to clipboard
A clean, UI-agnostic form state and validation system for Flutter.
0.2.0 #
This release makes fabrik_forms usable for real forms. The headline change is
that a form is no longer locked to a single field type.
Breaking #
-
Changed:
FabrikForm,FabrikFormNotifier, andFabrikFormBuilderno longer take a type parameter. A form previously had oneTfor every field, so a signup form with aStringemail, anintage, and aboolopt-in could not be expressed — the shipped example wasFabrikFormNotifier<String>for exactly this reason. Each field now carries its own type and its own validators, and types are recovered at the call site withget<T>('key').// before FabrikForm<String>({ 'email': FabrikField(value: '') }); // after FabrikForm({ 'email': FabrikField<String>(value: '', validators: [EmailValidator()]), 'age': FabrikField<int>(value: 0, validators: [RangeValidator(min: 18, max: 120)]), 'subscribed': FabrikField<bool>(value: false), });To migrate, drop the type argument from
FabrikForm<T>/FabrikFormNotifier<T>/FabrikFormBuilder<T>and put it on eachFabrikField<T>instead. Declaring a field without its type argument makes it aFabrikField<dynamic>;get<T>then throws aStateErrortelling you which declaration to annotate. -
Changed:
RangeValidatoris now generic overnumsubtypes, so it attaches to aFabrikField<int>orFabrikField<double>rather than onlyFabrikField<num>. ExistingRangeValidator(min:, max:)call sites are unaffected. -
Changed:
PasswordValidatorchecksminLengthbefore the uppercase, digit, and special-character rules, so the most basic failure is reported first. A short password that satisfies the character rules now reports the length message instead of passing those checks and reporting length last.
New #
- New: Form-level validators for rules that span multiple fields, passed via
FabrikForm(fields, validators: [...])and surfaced throughformError/formErrors. They count towardsisValid.FieldsMatchValidator— the password-confirmation case, ready made.FabrikFormRule— wraps a plain function for one-off rules.FabrikFormValidator— the base class for custom rules.
- New:
FabrikField.errorsandvisibleErrorsreturn every failing rule, alongside the existing first-errorerrorandvisibleError.FabrikForm.allErrorsexposes the same per field. - New:
FabrikForm.contains(key)andFabrikForm.keysfor inspecting the field set.
Fixes #
- Fix: Looking up an unknown field key threw
Null check operator used on a null value, naming neither the key nor the valid ones.getandupdatenow throw anArgumentErrorthat names the missing key and lists the available fields.
Tests #
- Test suite grown from 98 to 136 tests, covering mixed-type forms, cross-field validation, multi-error reporting, and the lookup failure modes.
0.1.0 #
- New:
UrlValidator— validates HTTP/HTTPS URLs with optionalrequireHttpsflag - New:
PhoneValidator— validates common local and international phone formats - New:
RangeValidator— validates that a numeric value falls within an inclusivemin..maxrange - New:
FabrikField.reset()— restores field to its initial value and clears touched/dirty state - New:
FabrikForm.reset()— resets all fields at once - New:
FabrikFormNotifier.reset()— resets the form and notifies listeners - New:
PasswordValidator.isRequired— allows optional password fields (mirrorsEmailValidator) - Fix:
EmailValidator— empty value withisRequired: falsenow correctly returnsnullinstead ofinvalidMessage - Improvement:
PasswordValidatorspecial character set expanded to include-,_,+,=,[,],/,~, and` - Tests: Added full test suite — 98 tests across validators,
FabrikField,FabrikForm, andFabrikFormNotifier
0.0.1 #
FabrikField<T>withvalue,error,isTouched,isDirty,visibleErrorFabrikForm<T>with field management, validation, andmarkAllTouched()FabrikFormNotifier<T>for reactive usageFabrikFormBuilder<T>for clean widget-building- Built-in validators:
RequiredValidatorMinLengthValidatorMaxLengthValidatorEmailValidatorPasswordValidator