validator method

  1. @override
FutureOr<Result> validator(
  1. dynamic value
)
override

Implementation

@override
FutureOr<Result> validator(dynamic value) {
  var currentValue = value;
  final aggregatedExpectations = <Expectation>[];

  for (var i = 0; i < validators.length; i++) {
    final inputValue = _config.chainsValues ? currentValue : value;
    final result = validators.elementAt(i).validator(inputValue);

    if (result is Future<Result>) {
      return _continueAsync(result, i + 1, currentValue, value, aggregatedExpectations);
    }

    final (shouldStop, stopResult) =
        _processResult(result, inputValue, aggregatedExpectations);
    if (shouldStop) return stopResult!;

    if (_config.chainsValues && result.isValid) currentValue = result.value;
  }

  return _buildFinalResult(
      _config.chainsValues ? currentValue : value, aggregatedExpectations);
}