validator property
validator
for the DropdownTextField
to make use of this validator, The
SearchField widget needs to be wrapped in a Form
and pass it a Global key
and write your validation logic in the validator
you can define a global key
Form(
key: _formKey,
child: SearchField(
suggestions: _statesOfIndia,
validator: (state) {
if (!_statesOfIndia.contains(state) || state.isEmpty) {
return 'Please Enter a valid State';
}
return null;
},
)
You can then validate the form by calling the validate function of the form
_formKey.currentState.validate();
Implementation
final String? Function(String?)? validator;