TextFormField validation shows no any effect for the validator used

Issue

Hi I am currently trying to validate a text and number field and using TextFormField widget but even though i have defined validator, it gives no any effect.

   TextFormField(
              controller: _zipcode,
              keyboardType: TextInputType.number,
              validator: (value) {
                if (value==null || value.isEmpty ) {
                  return "Enter correct value";
                } else {
                  return null;
                }
              },
              decoration: InputDecoration(
                  labelText: 'Mileage as shown in Odometer'),
            )

Solution

Have you used the Form() and assigned a key to the form? Please share your code to check if you have the Form() correctly.

Also, check this out. https://docs.flutter.dev/cookbook/forms/validation

Answered By – Carlos Sandoval

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published