validate method
Validates a value against this definition
Implementation
ValidationResult validate(dynamic value) {
// Check required
if (isRequired && (value == null || value.toString().trim().isEmpty)) {
return ValidationResult.error('The field "$displayName" is required');
}
// Skip validation if value is null and not required
if (value == null) {
return ValidationResult.success();
}
// Type validation
if (!_isValidType(value)) {
return ValidationResult.error(
'The field "$displayName" must be of type ${_getTypeName()}',
);
}
// Custom validation rules
for (final rule in validationRules) {
final result = _validateRule(rule, value);
if (!result.isValid) {
return result;
}
}
return ValidationResult.success();
}