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'),
)
2
Answers
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
Please check below code for the same with auto validation.