Question

How to Remove Error Message in TextFormField in Flutter

How can I remove the error message in TextFormField created by validator? I just want the red border because I don't have the space to show the error.

bool error = false;
 TextFormField ( 
      hintText:error?'please input productName':'',
      hintStyle:TextStyle(color: Colors.red), 
      validator:(v){  
       v.trim().length>0?error=false:error=true; return null; 
      }
 ) 
 46  46124  46
1 Jan 1970

Solution

 92

Try the code bellow. No size adjustment for the error text, only the field border in red.

 TextFormField(
  decoration: InputDecoration(
    errorStyle: TextStyle(height: 0),
  ),
);
2020-02-13

Solution

 12

This worked for me. I like how it turned out.

No size adjustment or anything like that happens.

In the Constructor of TextFormField...

decoration: InputDecoration(
        isDense: true,
        contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
        errorMaxLines: 1,
        errorText: '',
        errorStyle: TextStyle(
          color: Colors.transparent,
          fontSize: 0,
          ),
         ),

If you want you could show errors on SnackBar...

2020-02-02