FormErrors.from constructor

FormErrors.from(
  1. Object? value
)

Creates validation errors from common error response shapes.

Implementation

factory FormErrors.from(Object? value) {
  if (value == null) return const FormErrors();
  if (value is FormErrors) return value;
  if (value is Map<String, String>) {
    return FormErrors({
      for (final entry in value.entries) entry.key: [entry.value],
    });
  }
  if (value is Map) {
    final source = _extractErrorMap(value);
    return FormErrors({
      for (final entry in source.entries)
        entry.key.toString(): _normalizeMessages(entry.value),
    });
  }

  return const FormErrors();
}