errors property

A map of all current validation errors keyed by their FormKey.

This getter filters the validation results to only include fields with validation errors. For asynchronous validations that are still pending, a WaitingResult is included to indicate the validation is in progress.

Returns a Map<FormKey, ValidationResult> containing only fields with errors.

Implementation

Map<FormKey, ValidationResult> get errors {
  final errors = <FormKey, ValidationResult>{};
  for (var entry in _validity.entries) {
    var result = entry.value.result;
    if (result is Future<ValidationResult?>) {
      errors[entry.key] =
          WaitingResult.attached(state: entry.value.state, key: entry.key);
    } else if (result != null) {
      errors[entry.key] = result;
    }
  }
  return errors;
}