nullable function
- IValidator validator
If the field is not present (null) it will be considered valid If you want to allow empty strings as valid, use optional instead
Example
final isValid = nullable(isString()).validate(null); // true
final isValid = nullable(isString()).validate(''); // true
final isValid = nullable(isString()).validate(false); // false
// It works a bit differently on maps:
final validListField = eskema({
'nullable': nullable(isString()),
});
validListField.isValid({'nullable': 'test'}); // true
validListField.isValid({'nullable': ''}); // true
validListField.isValid({'nullable': null}); // true
// If the field does not exists on the map, it's considered invalid.
// You can use the `optional` validator to allow missing fields.
validListField.isValid({}); // false
Implementation
IValidator nullable(IValidator validator) => validator.nullable();