Skip to content

Replace the new InputDecorator.error with errorBuilder or add TextFormField.validatorBuilder #135292

Closed

Description

@TheLastFlame

Is there an existing issue for this?

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
Add Widget error in InputDecoration
Add a validator variant: Widget? Function(String? input)? validatorBuilder in FormField. 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
Add Widget Function(String)? errorBuilder on InputDecoration which when not null is called to convert errorText to 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

  1. Farma20 commented on Sep 22, 2023

    @Farma20
  2. added
    in triagePresently being triaged by the triage team
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    c: proposalA detailed proposal for a change to Flutter
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 22, 2023
  3. TheLastFlame commented on Sep 23, 2023

    @TheLastFlame
    ContributorAuthor

    Examined these two options in a bit more detail

    FormField.validator sets the value of the FormFieldState._errorText parameter, which is RestorableStringN.
    If we implement validatorBuilder similarly to validator, we find that RestorableWidget does 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 TextFormField depends on FormField.
    And DropdownButtonFormField and CupertinoTextFormFieldRow simply do not need such an addition.
    Accordingly, adding this functionality to FormField is 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 errorBuilder as originally intended. To be honest, I don't understand the reasons why the author of #118610 abandoned this solution and converted it into an error parameter.

  4. Renzo-Olivares commented on Sep 27, 2023

    @Renzo-Olivares
    Contributor

    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.

  5. added
    triaged-designTriaged by Design Languages team
    P2Important issues not at the top of the work list
    on Sep 27, 2023
  6. TheLastFlame commented on Sep 29, 2023

    @TheLastFlame
    ContributorAuthor

    @Renzo-Olivares, To be honest, I have already implemented errorBuilder xD

    I honestly don't like the validatorBuilder idea because of the issues mentioned above
    Can 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?

    errorBuilder is decoupled from FormField, which does not need such functionality. Accordingly, the api remains the same validator/errorText. And errorBuilder just controls the display of errorText. Again, as I wrote above, the name validatorBuilder does not reflect reality and is confusing.

  7. allanwolski-openco commented on Jul 17, 2024

    @allanwolski-openco

    errorBuilder would be great, any updates?

  8. justinmc commented on Dec 5, 2024

    @justinmc
    Contributor

    This issue would be solved by something like this closed PR: #157087

    See also #156275 for the ideas that led to the PR above.

  9. added
    has partial patchThere is a PR awaiting someone to take it across the finish line
    and removed
    team-designOwned by Design Languages team
    on Dec 5, 2024
  10. flutter-triage-bot commented on Dec 5, 2024

    @flutter-triage-bot

    The triaged-design label is irrelevant if there is no team-design label or fyi-design label.

  11. github-actions commented on Feb 13, 2025

    @github-actions

    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 -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Feb 13, 2025
  13. added a commit that references this issue on Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.has partial patchThere is a PR awaiting someone to take it across the finish linep: material_uimaterial_ui package in flutter/packagesteam-text-inputOwned by Text Input team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions