Search code examples
flutterflutter-text

Showing an error under a TextField in Flutter


Material design allows a text field to indicate an error via a small red label under the input box: https://material.io/components/text-fields (see screenshot below).

Is there a way to achieve this for a TextField field in Flutter? I expected this to be a property of either TextField or TextEditingController, but haven't found anything like it.

Screenshot showing how a textfield with an error looks like


Solution

  • It is present in the decoration property in TextField, also you can style it using it's style property.

         TextField(
            decoration: InputDecoration(
              errorStyle: TextStyle(),
              errorText: 'Please enter something'
            ),
          ),