Flutter Forms: Is there a way to change the color of the input text based on some condition?

262 Views Asked by At

Is there a way to change the colour of the input text based on some condition ? The inputFormatters only seem to apply to structuring the input.

1

There are 1 best solutions below

0
On

You can change the input text color using TextStyle

Here is a code sample:

TextField(
  style: TextStyle(color: Colors.green),
  ...
)

You can introduce a condition using a boolean called 'myCondition' and a Ternary Operator in the following way:

TextField(
      style: TextStyle(color: myCondition ? Colors.red : Colors.blue),
  ...
    )

https://api.flutter.dev/flutter/painting/TextStyle-class.html