validate method

  1. @override
void validate(
  1. String? path,
  2. Schema schema,
  3. dynamic value,
  4. List<ValidationResult> results,
)
override

Validates the given value. None of the values set in this ExcludedRule object must exist in the value that is given for validation to pass.

  • path the dot notation path to the value that is to be validated.
  • schema (not used in this implementation).
  • value the value that is to be validated.
  • results the results of the validation.

Implementation

@override
void validate(String? path, Schema schema, dynamic value,
    List<ValidationResult> results) {
  if (_values.isEmpty) return;

  var name = path ?? 'value';
  var found = false;

  for (var i = 0; i < _values.length && !found; i++) {
    var thisValue = _values[i];

    if (ObjectComparator.compare(value, 'EQ', thisValue)) {
      found = true;
      break;
    }
  }

  if (found) {
    results.add(ValidationResult(
        path,
        ValidationResultType.Error,
        'VALUE_INCLUDED',
        name + ' must not be one of ' + _values.join(','),
        _values,
        null));
  }
}