maybeWhen<R> method
R
maybeWhen<R>({
- required R orElse(),
- R loading()?,
- R success(
- T data
- R error(
- Object? error
- R empty()?,
- 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();
}