when<R> method

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

Implementation

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