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;
}
)
clear), // clear text onPressed: clearText, ), ), controller: fieldText, ), In the above-mentioned code, there is a TextField and suffixIcon is added to it as a decoration. The clearText method is the same as used in the above code.
Use the enabled: property of the TextField widget by setting it to false : TextField( enabled: false, ... ) This field won't respond to onTap events - it is similar to a disabled field in HTML.
You can control the TextField in your Flutter App. The TextField widget of Flutter has an inbuilt method TextEditingController. clear() which is used to clear or empty the typed text inside the Text Input widget. The clear() method would empty the entered string text and set its default value is empty.
You can return an empty string which will still mark the borders red if not valid
validator: (String value) {
if (value.isEmpty) {
return '';
}
},
UPDATE
What I did to fix that was wrap the TextField with SizedBox and give a fixed height then want expand with error message
SizedBox(
height: SOME_FIXED_HEIGHT_INCLUDING_ERROR_MESSAGE'S_HEIGHT,
child: TextField()
Try the code bellow. No size adjustment for the error text, only the field border in red.
TextFormField(
decoration: InputDecoration(
errorStyle: TextStyle(height: 0),
),
);
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With