validateStrict method
Validates the object strictly, including type checks for each field.
Implementation
@override
Object? validateStrict(Map<String, dynamic>? value, {bool returnAllErrors = false, bool returnAsList = false}) {
if (value == null) return invalidTypeMessage;
List<String> errors = [];
// Check for missing required fields
for (var key in _schema.keys) {
if (!_optionalFields.contains(key) && !value.containsKey(key)) {
errors.add("$key is required");
}
}
// Validate unexpected keys
if (!_allowExtraKeys) {
final extraKeys = value.keys.toSet().difference(_schema.keys.toSet());
if (extraKeys.isNotEmpty) {
errors.add("Unexpected keys found: ${extraKeys.join(', ')}");
}
}
// Validate fields against their respective validators
_validateSchemaStrict(value, errors, returnAllErrors, returnAsList);
return returnAllErrors ? errors : (errors.isNotEmpty ? errors.first : null);
}