validate method
Validate this
instance with validate
.
Returns defaultValue
if not valid or value is null.
Implementation
FutureOr<T?> validate(FutureOr<bool> Function(T val)? validate,
{T? defaultValue}) {
if (validate == null && defaultValue == null) {
return this;
}
var self = this;
if (self is Future<T>) {
return self.then((value) =>
_validate(value, validate: validate, defaultValue: defaultValue)
as FutureOr<T>);
} else {
return _validate(self, validate: validate, defaultValue: defaultValue);
}
}