setError method
Sets an error message for the specified field and updates the form state to invalid.
This method directly assigns the provided error message to the specified field and
updates the form's status to BondFormStateStatus.invalid.
fieldNameThe name of the field to set the error for.errorThe error message to set for the field.
Implementation
void setError(String fieldName, String? error) {
final field = state.get(fieldName);
state.fields[fieldName] = field.updateError(error);
var status = state.status;
if (error != null) {
status = BondFormStateStatus.invalid;
} else if (state.status == BondFormStateStatus.invalid ||
state.status == BondFormStateStatus.pristine) {
// Only promote to valid if all fields are now valid
status = _allValid(false)
? BondFormStateStatus.valid
: BondFormStateStatus.invalid;
}
state = state.copyWith(
fields: Map.from(state.fields),
status: status,
);
}