Remove error message in TextFormField in Flutter

Viewed 224

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

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.

Related