-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add Form field autovalidation API migration guide #4512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5d5e1f3
86c66c9
c3a3770
06011fa
ec357f9
7c692fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| --- | ||
| title: The new Form, FormField auto-validation API | ||
| description: Gives more control in how we want to auto validate a Form, FormField | ||
| --- | ||
|
|
||
| ## Summary | ||
|
|
||
| In the previous auto validation API of Flutter for the `Form` and `FormField` we were not able to control | ||
| when the auto validation should occur. So the auto validation for these widgets always happened on first | ||
| build when the widget is first visible to the user, and you were not able to control when the auto | ||
| validation should happen. | ||
|
|
||
| ## Context | ||
|
|
||
| Due to the original API not allowing developers to change the auto validation behaviour for things like: | ||
|
|
||
| 1. Validate only when the user interacts with the form field. | ||
|
|
||
| We come up with the new `AutovalidateMode` API that gives developers to configure how they want | ||
| the auto validation API to behave. | ||
|
|
||
| ## Description of change | ||
|
|
||
| Here ate the changes made to address the above problems: | ||
pedromassango marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 1. The `autovalidate` parameter has been deprecated. | ||
| 2. We added a new parameter called `autovalidateMode` it is an Enum that accepts values from the | ||
| `AutovalidateMode` Enum class. | ||
|
|
||
|
|
||
| ## Migration guide | ||
|
|
||
| To migrate to the new auto validation API you need to replace the usage of the deprecated | ||
| `autovalidate` parameter to the new `autovalidateMode` parameter. If you want to have the same behavour | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be "with the new" instead of "to the new". |
||
| as before you can use: `autovalidateMode = AutovalidateMode.always`, this will make your `Form`, `FormField` | ||
| widget to auto validate on first build and every time it changes. | ||
|
|
||
| Code before migration: | ||
|
|
||
| ```dart | ||
| class MyWidget extends StatelessWidget { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return FormField( | ||
| autovalidate: true, | ||
| builder: (FormFieldState state) { | ||
| return Container(); | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| <!-- skip --> | ||
| ```dart | ||
| class MyWidget extends StatelessWidget { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return FormField( | ||
| autovalidateMode: AutovalidateMode.always, | ||
| builder: (FormFieldState state) { | ||
| return Container(); | ||
| }, | ||
| ); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Timeline | ||
|
|
||
| Landed in version: 1.19<br> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be landed 1.20 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the PR that deprecate the autovalidate parameter needs an update too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a new PR that apply the suggestions. #4512 |
||
| In stable release: not yet | ||
|
|
||
| ## References | ||
|
|
||
| API documentation: | ||
| * [`AutovalidateMode`](https://master-api.flutter.dev/flutter/widgets/AutovalidateMode-class.html) | ||
|
|
||
| Relevant issues: | ||
| * [Issue 56363](https://github.com/flutter/flutter/issues/56363) | ||
| * [Issue 18885](https://github.com/flutter/flutter/issues/18885) | ||
| * [Issue 15404](https://github.com/flutter/flutter/issues/15404) | ||
| * [Issue 36154](https://github.com/flutter/flutter/issues/36154) | ||
| * [Issue 48876](https://github.com/flutter/flutter/issues/48876) | ||
|
|
||
| Relevant PRs: | ||
| * [FormField should autovalidate only if its content was changed](https://github.com/flutter/flutter/pull/56365) | ||
| * [FormField should autovalidate only if its content was changed (fixed)](https://github.com/flutter/flutter/pull/59766) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be past tense