I'm trying to validate different user inputs, and i want to inform them which input is null i tried to show an alert dialog whenever the user hit the submit button while an input is null, but then i got an error and it didn't open the page saying i have to fill the information before i even open the page. However i tried a something else but unfortunately it didn't work ether this is what i did.
TextFormField(
key: _formKey,
validator: (value) {
if (value == null) {
return 'please write a review';
} else if (DATA == null) {
return 'please select a category';
} else if (image == null) {
return 'please add an image';
} else if (tag == null) {
return 'please select sub category';
} else if (_descriptionController.text == null) {
return 'please select a location';
} else
return null;
},
maxLines: 20,
maxLength: 200,
controller: _descriptionController2,
decoration: InputDecoration(
contentPadding:
EdgeInsets.only(left: 10.0, top: 16.0),
hintText: "What do you think about the place?",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16.0)),
),
),
That's what i added to the button when it's pressed
onPressed: () {
bool valid = validation();
if (valid)
addData(image!, DATA!, lat, lng, _descriptionController2.text,
tag!, loggedInUser2!);
Navigator.pop(context);
},
lastly this is the validation method
bool validation() {
final form = _formKey.currentState;
if (form!.validate()) {
return true;
}
return false;
}
can any one help?