Autovalidate of TextFormField is deprecated in Flutter

8,658

Solution 1

autovalidate is replaced by autovalidateMode

Auto validation is deprecated and replaced by an enum. So you should migrate to the new version.

All you need to do is replace autovalidate: true with autovalidateMode: AutovalidateMode.always

The different supported modes are

  1. AutovalidateMode.always
  2. AutovalidateMode.disabled
  3. AutovalidateMode.onUserInteraction

Example:

Code before migration:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FormField(
      autovalidate: true,
      builder: (FormFieldState state) {
        return Container();
      },
    );
  }
}

Code after migration:

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FormField(
      autovalidateMode: AutovalidateMode.always,
      builder: (FormFieldState state) {
        return Container();
      },
    );
  }
}

Solution 2

autovalidate is deprecated from Flutter v1.19

Replace autovalidate with autovalidateMode.

autovalidateMode can have one of the below 3 values:

  1. autovalidateMode: AutovalidateMode.disabled: No auto validation will occur.

  2. autovalidateMode: AutovalidateMode.always: Used to auto-validate FormField even without user interaction.

  3. autovalidateMode: AutovalidateMode.onUserInteraction: Used to auto-validate FormField only after each user interaction.

I suggest try all the above values one by one and use the one that fulfills ur requirement.

Share:
8,658
Arnab Bhattacharya
Author by

Arnab Bhattacharya

Updated on December 24, 2022

Comments

  • Arnab Bhattacharya
    Arnab Bhattacharya over 1 year

    'autovalidate' is deprecated and shouldn't be used. Use autoValidateMode parameter which provide more specific behaviour related to auto validation. This feature was deprecated after v1.19.0.. Try replacing the use of the deprecated member with the replacement. enter image description here

    • sameer kashyap
      sameer kashyap over 3 years
      Can you specify what is the problem you are facing ?
  • bounxye
    bounxye over 2 years
    Has anyone used Autovalidate.disabled ? It's not working for me.