validate method
void
validate(
- String? path,
- Schema schema,
- dynamic value,
- List<
ValidationResult> results,
override
Validates a given value against this rule.
path
a dot notation path to the value.schema
a schema this rule is called fromvalue
a value to be validated.results
a list with validation results to add new results.
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_NOT_INCLUDED',
name + ' must be one of ' + _values.join(','),
_values,
null));
}
}