Repository navigation
Replace the new InputDecorator.error with errorBuilder or add TextFormField.validatorBuilder #135292
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Use case
InputDecorator.error added in #129275 is completely useless in its current form.
In fact, it is just a widget displayed under TextField, while blocking access to errorText, which completely breaks the existing validation mechanisms.
All interaction with this widget has to be done completely manually. If you put the TextField in Column, and our error widget under it, the effect will be exactly the same.
Because of this, closed #11068 is not actually resolved.
Proposal
#129275 is a fork of #118610, where this problem was discovered and discussion of possible solution methods began.
Four solutions to the problem were proposed in #118610 (comment), two of which were discarded.
Meanwhile, neither of the other two were implemented in #129275, for some reason approved for merging.
These options are:
Option 2
AddWidget errorinInputDecoration
Add a validator variant:Widget? Function(String? input)? validatorBuilderinFormField. It allows to replace the classical validator with a version that can return a Widget instead of a string.
This option was liked by @justinmc but wasn't implemented in #129275
Option 4
AddWidget Function(String)? errorBuilderonInputDecorationwhich when not null is called to converterrorTextto a Widget.
Both of these options solve the problem that has arisen.
I am willing to implement this, but I need approval and need to choose one of these options.
Activity
Farma20 commentedon Sep 22, 2023
TheLastFlame commentedon Sep 23, 2023
Examined these two options in a bit more detail
FormField.validatorsets the value of theFormFieldState._errorTextparameter, which isRestorableStringN.If we implement
validatorBuildersimilarly tovalidator, we find thatRestorableWidgetdoes not exist. So we need to create it. Which is hardly a good solution, given that it hasn't been done in so many years of Flutter's existence.Besides, not only
TextFormFielddepends onFormField.And
DropdownButtonFormFieldandCupertinoTextFormFieldRowsimply do not need such an addition.Accordingly, adding this functionality to
FormFieldis not a good idea.And finally I don't like the name validatorBuilder, which is confusing, making me think that this function creates validators and not error widgets.
I think it would be much better to implement the
errorBuilderas originally intended. To be honest, I don't understand the reasons why the author of #118610 abandoned this solution and converted it into anerrorparameter.Renzo-Olivares commentedon Sep 27, 2023
Hi @TheLastFlame, thank you for reporting this issue. This seems related to #133629. I think i'm still leaning towards option 2 described in this comment #118610 (comment) because it would keep the API consistent
(errorText/validator)/(error/validatorBuilder). We would definitely welcome a PR with this change, and I'd be happy to review it.TheLastFlame commentedon Sep 29, 2023
@Renzo-Olivares, To be honest, I have already implemented
errorBuilderxDI honestly don't like the
validatorBuilderidea because of the issues mentioned aboveCan you give your opinion on them?
Also, I don't understand how validatorBuilder is better at keeping the api consistent. We already have similar interfaces, why do we need to make similar ones?
errorBuilderis decoupled fromFormField, which does not need such functionality. Accordingly, the api remains the samevalidator/errorText. AnderrorBuilderjust controls the display oferrorText. Again, as I wrote above, the namevalidatorBuilderdoes not reflect reality and is confusing.allanwolski-openco commentedon Jul 17, 2024
errorBuilderwould be great, any updates?justinmc commentedon Dec 5, 2024
This issue would be solved by something like this closed PR: #157087
See also #156275 for the ideas that led to the PR above.
flutter-triage-bot commentedon Dec 5, 2024
The
triaged-designlabel is irrelevant if there is noteam-designlabel orfyi-designlabel.Add FormField.errorBuilder (#162255)
github-actions commentedon Feb 13, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Add FormField.errorBuilder (#162255)