setValue method
Set the value for a form attribute and optionally trigger validation.
The setValue function is used to set the value for a specific form attribute.
It first checks if the attribute exists in the _attributes map. If the attribute
exists, it clears any error messages for the attribute, updates the value in the
_values map, and updates the corresponding ValueNotifier. Depending on the
isAutoValidation flag, it may also trigger validation for the attribute.
Parameters:
attribute: The identifier of the form attribute for which you want to set the value.value: The value to be set for the specified form attribute.
Implementation
setValue(String attribute, dynamic value) {
if (!_attributes.containsKey(attribute)) {
return;
}
clearErrorMessages(attribute);
_values[attribute] = value;
getController(attribute).text = value?.toString() ?? '';
final modValue = _onBeforeSetValue(attribute, value);
_getValueNotifier(attribute).value = modValue;
if (isAutoValidation) {
validateAttribute(attribute, value);
} else {
clearErrorMessages(attribute);
}
}