maybeWhen<R> method

R maybeWhen<R>({
  1. R data(
    1. T data
    )?,
  2. R error(
    1. Object,
    2. StackTrace?,
    3. T? previous
    )?,
  3. R loading(
    1. T? previous
    )?,
  4. R nothing()?,
  5. required R orElse(),
})

Implementation

R maybeWhen<R>({
  R Function(T data)? data,
  R Function(Object, StackTrace?, T? previous)? error,
  R Function(T? previous)? loading,
  R Function()? nothing,
  required R Function() orElse,
}) {
  if (hasError && error != null) {
    return error(this.error!, stackTrace, this.data);
  }

  if ((connectionState == ConnectionState.active ||
          connectionState == ConnectionState.waiting) &&
      loading != null) {
    return loading(this.data);
  }

  if (hasData && data != null) {
    return data(this.data!);
  }

  if (nothing != null) {
    return nothing();
  }

  return orElse();
}