Flutter - can't see validation messages for disabled form fields
Asked Answered
T

2

8

For my Flutter App, I'm using many input form fields for data input, and assigning a validation method for each, for all fields the error message appears normally, just below the field, except for one field that takes value from a picker dialog, so that i made it disabled (enabled=false) to prevent user input on it

Is it normal that a disabled field doesn't show validation error messages? if yes, should i do something different to prevent user input on that field other than making it disabled?

Travertine answered 22/3, 2019 at 15:47 Comment(0)
K
37

Simply add an InputDecoration with an errorStyle to the TextFormField to use any color you want for the error, which applies for both enabled and disabled fields:

TextFormField(
  ...
  decoration: InputDecoration(
    errorStyle: TextStyle(
      color: Theme.of(context).errorColor, // or any other color
    ),
  ),
 ),
Kella answered 20/6, 2019 at 8:36 Comment(2)
Thanks for the very clean solution @Kella :)Cellist
This answer is kind of a miracle #KudosUlphiah
B
0

I think you can set readOnly=true instead enable=false

Bobodioulasso answered 28/5, 2024 at 12:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.