-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Use case
It would be nice to have a TextFormField that didn't show the error messages below when trying to do validation. For example, in my design, I chose to show the error messages interactively on the labelText.
Having no option of disabling the errorText can really be annoying when trying to deal with the spacing of the fields. You will either have to create an extra-padded TextFormField and let the errorText be always ' ', or live with the abrupt transition of when the error message appears and the spacing changes.
This has appeared in complaints before:
- StackOverflow — Flutter increase height of TextFormField
- Issue TextField height changes if the errorText shows #15400 — TextField height changes if the errorText shows
Proposal
I don't have a good solution for the abrupt transition when the errorText appears. Maybe showing it with some sort of AnimatedContainer would be a good option. (One solution that goes along those lines is this one).
However, when it comes to showing or not the errorText, I have a suggestion — also featured in this SO answer — that would change only 2 lines of the source's TextFormField:
- Add another parameter to the
TextFormField's constructor (below this line), say,errorTextPresent:// `true` is the current implicit default, i.e., showing the `errorText` bool errorTextPresent = true
- Change the decoration's initialization of the internal
TextFieldto feature the new option.- From:
decoration: effectiveDecoration.copyWith(errorText: field.errorText), - To:
decoration: effectiveDecoration.copyWith( errorText: errorTextPresent ? field.errorText : null)
- From:
- You can now call
TextFormFieldwith a new option when you wish to disable theerrorText:TextFormFieldWithErrorTextOption( errorTextPresent: false, // `false` will disable the `errorText` ... ),
Strictly speaking, this issue should probably have been a PR. But I chose it to be an issue because I didn't really know how the Flutter team would have liked to proceed.