maybeWhen<R> method

R maybeWhen<R>({
  1. required R orElse(),
  2. R loading()?,
  3. R success(
    1. T data
    )?,
  4. R error(
    1. Object? error
    )?,
  5. R empty()?,
  6. R custom()?,
})

Implementation

R maybeWhen<R>({
  required R Function() orElse,
  R Function()? loading,
  R Function(T data)? success,
  R Function(Object? error)? error,
  R Function()? empty,
  R Function()? custom,
}) {
  final self = this;
  if (self is LoadingStatus<T> && loading != null) {
    return loading();
  } else if (self is SuccessStatus<T> && success != null) {
    return success(self.data);
  } else if (self is ErrorStatus<T, dynamic> && error != null) {
    return error(self.error);
  } else if (self is EmptyStatus<T> && empty != null) {
    return empty();
  } else if (self is CustomStatus<T> && custom != null) {
    return custom();
  }
  return orElse();
}