resolve method

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

Resolves this instance.

  • validate if returns false will resolve to defaultValue.
  • If resolved value is null will return defaultValue.

Implementation

FutureOr<T> resolve(
    {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<T>(this as T,
        validate: validate, defaultValue: defaultValue) as FutureOr<T>;
  }
}