validate method

FutureOr<T?> validate(
  1. FutureOr<bool> validate(
    1. T val
    )?, {
  2. T? defaultValue,
})

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);
  }
}