runValidation method

(bool, T?) runValidation(
  1. ValidationTrigger? trigger
)

Implementation

(bool result, T? current) runValidation(ValidationTrigger? trigger) {
  bool hasGuardMatched = false;
  bool hasStateError = false;
  T? current;
  for (var i = 0; i < fields.length; i++) {
    final field = fields[i];
    field.performValidation(trigger);

    final fieldValue = field.getValue();
    final (results, isGuard) = _classValidator.annotateFieldExtended(field.fieldName, fieldValue);
    _errorBuffer.putAll(results);

    if (field.hasStateError) {
      hasStateError = true;
    }
    if (isGuard) {
      hasGuardMatched = true;
    }
  }

  if (!hasGuardMatched) {
    current = _readSilent();
    if (current != null) {
      final results = _classValidator.annotateExtended(current);
      _errorBuffer.putAll(results);
    }
  }

  _errorBuffer.recalculateFieldErrors();

  for (var value in fields) {
    value.handleErrors(_errorBuffer.fieldErrors[value.fieldName]!);
  }

  if (checkErrorStates && hasStateError) return (false, current);
  return (!_errorBuffer.hasErrors, current);
}