Amine Boujnah
Amine Boujnah

Reputation: 55

Remove error message in TextFormField in Flutter

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),
                  ),
                ),
              ),

Upvotes: 1

Views: 1615

Answers (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

Upvotes: 1

L. Gangemi
L. Gangemi

Reputation: 3290

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.

Upvotes: 3

Related Questions