setErrorMessages method
Set custom error messages for a form attribute.
The setErrorMessages
function is used to set custom error messages for a
specific form attribute. It first checks if the attribute exists in the
_attributes
map. If the attribute exists, it sets the custom error messages
in the _errors
map, triggering revalidation for the attribute by calling
validate()
on its associated form key. Additionally, it updates the error
notifier with the updated error messages.
Parameters:
attribute
: The identifier of the form attribute for which you want to set custom error messages.messages
: A list of custom error messages to be associated with the form attribute.
Implementation
setErrorMessages(String attribute, List<String> messages) {
if (!_attributes.containsKey(attribute)) {
return;
}
_errors[attribute] = messages;
getFormKey(attribute).currentState?.validate();
_getErrorNotifier(attribute).value = getErrorMessages(attribute);
}