Remove error message in TextFormField in Flutter
374
Solution 1
If you put your TextFormField
inside a Form
with the property autovalidateMode: AutovalidateMode.onUserInteraction
, the validation function should trigger when you select again or change the text.
If the validation function is satisfied, the error message will be removed.
Solution 2
You have to use the autoValidateMode method in TextFormField.
Here, is the some of the reference: https://api.flutter.dev/flutter/widgets/AutovalidateMode-class.html
Author by
Amine Boujnah
Updated on December 30, 2022Comments
-
Amine Boujnah 20 minutes
Hi I want to remove error message caused by validator in TextFormField widget after I submit a form in flutter. Ps : I want the error message disappeared after I select again the TextFormField to write into it again.
TextFormField( controller: _emailController, keyboardType: TextInputType.emailAddress, textInputAction: TextInputAction.next, validator: (value) { if (value == null || value.isEmpty || !EmailValidator.validate(value)) { return nullEmailMsg; } return null; }, decoration: InputDecoration( hintText: emailHint, prefixIcon: Icon(Icons.mail), border: OutlineInputBorder( borderRadius: BorderRadius.circular(10), ), ), ),