reactive_forms: ^10.2.0 copied to clipboard
This is a model-driven approach to handling form inputs and validations, heavily inspired in Angular Reactive Forms.
- Fix error when defining a ReactiveTextField with dynamic type and bound the widget with controls other than String.
- Add the optionally extra argument autoValidate to the method AbstractControl.setValidators to recalculate the validaity of the control after set the new validators without explicitly call updateValueAndValidity on that control.
- Add minor changes in Validators.min and Validators.max for handlig type checks
- Add minor changes in ReactiveValueListenableBuilder for handlig type checks
Breaking changes #
- Reactive Forms is now migrated to Flutter 2.x.
- Reactive Forms is now Null-safety.
- New Definitions in Custom Reactive Widgets. ReactiveFormField now defines the data type of the model (control) and the data type of the view (widget).
- Validators.requiredTrue now has the 'requiredTrue' validation message and not 'requiredEquals' as in previous versions.
- Now you can specify a different validation message to the Validators.pattern validator.
- Remove Validators String type to fix casts errors when calling form.control('').validators in a control with a non dynamic type validator.
- Add minor changes to successfully pass pub dev static analysis.
- Add Library documentation.
Breaking changes #
- An enhanced strongly typed system to improve casting at compilation time and improve casting exception handler in runtime. This version was created to be compatible with analysis options in "implicit-casts: false" and "implicit-dynamic: false".
- If a control is disabled, then it doesn't fire state change again when call markAsDisabled.
- Set cursor at the end of the text when set value to reactive text field from the FormControl.
- Expose focus controller of the FormControl. Now is possible to access UI FocusNode with in a control through control.focusController.focusNode.
- A disabled ReactiveDropdownField now tale into account the selectedItemBuilder method to show the disabledHint.
- More complete example app project inside Reactive Forms.
- Add FormGroup.rawValue and FormArray.rawValue to get the value of groups and array including any disabled controls.
- Add method patchValue to FormControl, FormGroup and FormArray to update partially the control value.
- Add async validators to FormGroup and FormArray.
- Add disabled optional argument to FormArrayConstructor.
- Initialize a FormGroup as disabled is now possible with optional constructor argument.
- Add new control value accessor Iso8601DateTimeValueAccessor that brings the possibility to bind a ReactiveDateTimePicker widget to a control of type String.
- Fix when the execution of asynchronous validators completes the control is not marked as dirty.
Breaking changes #
- Change ReactiveFormField.validationMessages from a Map to a Function that receives the instance of the control and returns the Map with the customized validation messages. This upgrade now brings the possibility to dynamically change the validation messages based on the current error data.
- Change Validators.email response error Map. Now returns the current control value instead of true.
- Add AbstractControl.hasError(...) for asking if a control has an error based on error code and children path.
- Add AbstractControl.getError(...) to get error data based on error code and children path.
- Fix error when trying to get a deep control within an array of groups.
- Fix minor issues
- Fix some typos.
- Fix ReactiveDatePicker error when lastDate is previous to DateTime.now() and control value is null.
- FormArray.removeAt now returns the removed control.
- Improve code documentation.
- Add more tests.
- Add more strict data types in arguments.
- Add extra arguments to AbstractControl.setErrors and AbstractControl.removeError to marks the control as dirty or pristine.
- Refactor Validators.minLength and Validators.maxLength to be use with:
- FormControl of type Iterable
- FormControl of type String
- Add better data types definition in FormBuilder.array declaration.
- Changes all arguments of data type Iterable with List data type to force compiler errors when not correctly cast MappedListIterable with List.
- Fix control value accessor that doesn't update the control when LengthLimitingTextInputFormatter reached the max length.
Breaking changes #
- Add big refactor in focus handlers of a FormControl. Change argument data type in FormControl.focusChanges event, from FocusEvent to bool.
- Fix infinity loop that freeze apps when two or more ReactiveTextField were binded to the same FormControl and changing focus between them.
- Fix FormGroup.addAll now updates group pristine/dirty state of the group and trigger FormControlCollection.collectionChanges event.
- Add FormArray.clear() that remove all children controls of the array.
- Add optionally argument showErrors to ReactiveTextField and ReactiveDropdownField to customize when to show up validations messages. Validation messages by default change to visible when control is invalid and touched. With showErrors function this default behavior can be customized.
Breaking changes #
- Rename FormControl.focused by FormControl.hasFocus.
- Change ReactiveFormBuilder.builder(context) by ReactiveFormBuilder.builder().
- Change argument in FormControl.focusChanges event from bool to FocusEvent.
- Add FormGroup.unfocus() and FormArray.unfocus() to remove focus of children controls.
- Add FormArray.focus(String name) to set focus on a control.
- Add optional argument to AbstractControl.unfocus(bool touched) to mark controls as untouched when remove focus.
- Add optional argument to AbstractControl.reset(bool removeFocus) to remove focus on control when reset the control/form/array.
- Fix ReactiveFormBuilder initializations in debug mode.
- Fix add custom valueAccessor to text field.
- Fix Validators.min and Validators.max with non comparable controls.
Breaking changes #
- Rename touch() and untouch() by markAsTouched() and markAsUntouched()
- Rename enable() and disable() by markAsEnabled() and markAsDisabled()
- Add AbstractControl.markAllAsTouched to mark all controls of a FromGroup or a FormArray as touched. AbstractControl.markAsTouched doesn't marks children as touched anymore.
- Validators.compose now act as and AND and returns a ValidatorFunction instead of a List of ValidatorFunction
- InputParsers have been replaced by ControlValueAccessor.
- Add new control status pristine and dirty.
- FormGroup.control(String name) and FormArray.control(String name) now let specify the name argument as a dot-delimited string that represents the path to the nested control as nested1.nested2.nested.3.etc.
- Add FormBuilder.array() and FormBuilder.control() for creating arrays and controls.
- ReactiveValueListenableBuilder brings now the possibility to provide directly the control instead of just the control name.
- Add Validators.composeOR to combines multiples validators in one and evaluates as an OR, if at least one validator evaluates to VALID then the control is valid.
- Add ControlValueAccessor to convert value data types from UI to model and vice versa.
- Add FormGroup.focus(String name) to set focus to a child control.
- Add ReactiveFormBuilder useful for defining a FormGroup and a ReactiveForm at the same time in a stateless widget.
- Add validators:
- ReactiveRadioListTile widget is now available.
- Fix FormBuilder.group() with initial value in null.
- Add FormBuilder.state to create a ControlState.
- Fix async update in InheritedStreamer widget that raised exception when declare a form group in a stateless widget.
- FormControl.reset() can now set the disabled status of the control as an optional argument.
- Implements FormGroup.resetState() and FormArray.resetState() to reset children controls with initial value and disabled status.
Breaking Changes #
- FormControl constructor receives value instead of defaultValue. To reset a control to a initial value you must call FormControl.reset() and supply initial value.
- Fix Luhn algorithm in credit card validator.
- FormGroup.reset() marks control as untouched and hide UI validation errors.
- FormGroup.reset() sets empty string to input text fields if control value is null.
- InputParser added to ReactiveTextField. Now you can declare a FormControl with int or double data type and bind it to an input text field.
- Fixed card number length in Validators.creditCard
- Minor changes and code documentation.
- New Validator
- Validators.creditCard that validates a credit card number using the Luhn algorithm.
- Optimized FormGroup and FormArray value gets.
- FormBuilder docs added to README.md
- fixed ReactiveDropdownField.onChanged not triggered when control value didn't changes
- Minor fixes in ReactiveDropdownField.
- Minor fixes.
- Added basic implementation of FormBuilder to build FormGroup easily.
- Added onChanged callback to ReactiveDropdownField.
- Now ReactiveDropdownField not set value of control to null when no matching item founded.
- Added onWillPop to ReactiveForm widget.
- Enable/disable controls, groups and arrays.
- Now you can access the parent group or array with the property FormControl.parent.
- Removed restriction of empty item's array in ReactiveDropdown.
- Assert error in ReactiveDropdown when control value not match any item values.
- Slider assert error when control bounded to slider initialize in null value.
Breaking Changes #
- Use of Streams to notify events.
- Renamed event names.
See Migration Guide to see how to migrate from version 1.x to 2.x.
- Async validators now have a debounce timer in milliseconds that can be passed as argument to FormControl. This is useful for example to reduce requests to an API.
- Now you can optionally pass a FormControl directly to reactive widgets instead of the control's name. You must provide a formControlName or a formControl but not both at the same time.
- Set value an array value to FormArray insert missing items
- Composing validators with Validators.compose
- Added optionally type to ReactiveFormArray widget
Added utilities an extensions to AbstractControl
- AbstractControl.isNullOrEmpty for controls of type String
- FormArray and FormGroup now notify value changes when a control without validators changes its value.
FormGroup.touch mask all controls as touched.
Renamed FormGroup.formControl to FormGroup.control and FormArray.formControl to FormArray.control to get controls by name.
ReactiveValueListenableBuilder.builder now pass the control as parameter instead of the value so you can get access to the control within the builder function.
Added FormGroup.controls and FormArray.controls to iterate over child controls.
- Fixed ReactiveCheckbox and ReactiveCheckboxListTile exception when binding with FormControl with null value.
- Increased code tests coverage to 92% (a lot of tests).
- FormArray.removeAt method added to remove a control given the index position.
- Added ReactiveTextField.onSubmitted for an example of how to handle moving to the next/previous field when using TextInputAction.next and TextInputAction.previous for textInputAction.
- Included property ReactiveSwitchListTile.inactiveThumbImage.
- Included properties autofocus to ReactiveCheckbox, ReactiveRadio and ReactiveSwitch.
- Included callbacks ReactiveSlider.onChangeEnd and ReactiveSlider.onChangeStart.
New Validators #
- Async Validators (only FormControl for now...)
- Controls have now three different states: VALID, INVALID, PENDING (this last one was specially included due to async validators, the control is PENDING until validator completes)
- Added documentations about Validator.pattern
- Added Async Validator's example in example application /example/main.dart.
New Models #
- FormArray (aggregates the values of each child FormControl into an array)
New Reactive Widgets: #
- Added class ValidationMessage for common validation messages key as: required, email, etc.
- Added Documentation of ValidationMessage.
- Minor typo fix in documentation text.
- Added an example application
Predefined validators #
Supported Reactive Form Fields Widgets #
Other Reactive Forms Widgets #