Home > Back-end >  how to change color on TextFormField validator: (value) => validateCharacters(value),
how to change color on TextFormField validator: (value) => validateCharacters(value),

Time:09-13

I want to change this color to grey But but its red How can I achieve that or is it possible or not? code:

    TextFormField(
                  autovalidateMode: AutovalidateMode.onUserInteraction,
//Want to change color HERE
                  validator: (value) => validateCharacters(value), 
                  inputFormatters: [
                    LengthLimitingTextInputFormatter(20),
                  ],
                 
                  },
                ),

String? validateCharacters(String? value) {
  String pattern = (r'^(?=.*?)(?=.*?[a-z])(?=.*?[20]).{20,}$');
  RegExp regex = RegExp(pattern);
  if (value == null || value.isEmpty || !regex.hasMatch(value)) {
    return 'note: `Only 20 characters allow`'; //Want this to be grey color
  } else {
    return null;
  }
}

CodePudding user response:

You can add a error style inside decoration.

Check this:

TextFormField(
        autovalidateMode: AutovalidateMode.onUserInteraction,
        validator: (value) => validateCharacters(value), 
        decoration: InputDecoration(
           errorStyle: TextStyle(color: Colors.grey)
        ),
        inputFormatters: [
          LengthLimitingTextInputFormatter(20),
        ],
                     
      },
     ),

CodePudding user response:

If we want to change validation text color then put in to the decoration property in error style according to your UI.

TextFormField( autovalidateMode: AutovalidateMode.onUserInteraction, validator: (value) => validateCharacters(value), decoration: enter code hereInputDecoration(errorStyle: TextStyle(color: Colors.grey)),)

`

CodePudding user response:

You have to use

decoration: InputDecoration(
    errorStyle: TextStyle(color: Colors.red)
 ),

in your TextFormField

  • Related