setErrors method

void setErrors(
  1. Map<String, String?>? newErrors
)

Sets errors in fields as a Map, where key is the name of the field and value is the text of the error message.

Can be null if there are no errors.

Implementation

void setErrors(Map<String, String?>? newErrors) {
  errors = newErrors;

  EasyFormFieldState? errorField;

  for (final EasyFormFieldState<dynamic> field in _fields) {
    if (errors != null && errors!.containsKey(field.name)) {
      final bool hasError = errors![field.name]?.isNotEmpty ?? false;
      if (hasError && errorField == null) errorField = field;

      field._setErrorText(errors![field.name], silent: true);
    } else {
      field._setErrorText(null, silent: true);
    }
  }

  _focusField(errorField);

  _forceRebuild();
}