addFieldError method
If isPermanent
is false
, add an error to FieldBlocState.error.
Else if isPermanent
is true
Add a validator
that returns error
when the value
is the current value.
and then validate the fieldBloc
.
It is useful when you want to add errors that
you have obtained when submitting the FormBloc
.
Implementation
void addFieldError(Object error, {bool isPermanent = false}) {
if (isPermanent) {
final wrongValue = value;
addValidators(
[(value) => value == wrongValue ? error : null],
forceValidation: true,
);
} else {
emit(state.copyWith(
isValidated: false,
isDirty: true,
error: Param(error),
) as State);
}
}