Skip to content

Solution Proposal for showing or not the errorText in the TextFormField #52634

@psygo

Description

@psygo

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:

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:

  1. 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 
  2. Change the decoration's initialization of the internal TextField to feature the new option.
    1. From:
      decoration: effectiveDecoration.copyWith(errorText: field.errorText),
    2. To:
      decoration: effectiveDecoration.copyWith(
          errorText: errorTextPresent ? field.errorText : null)
  3. You can now call TextFormField with a new option when you wish to disable the errorText:
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: text inputEntering text in a text field or keyboard related problemsc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions