SideEffects<T>.onOrElse constructor
SideEffects<T>.onOrElse ({
- void onWaiting()?,
- void onError(
- dynamic err,
- VoidCallback refresh
- void onData(
- T data
- required void orElse(
- T data
- void initState()?,
- void dispose()?,
Handle the three state status with one required fallback callback.
Implementation
factory SideEffects.onOrElse({
void Function()? onWaiting,
void Function(dynamic err, VoidCallback refresh)? onError,
void Function(T data)? onData,
required void Function(T data) orElse,
void Function()? initState,
void Function()? dispose,
}) {
return SideEffects(
initState: initState,
dispose: dispose,
onSetState: (snap) {
if (snap.isWaiting && onWaiting != null) {
onWaiting();
return;
}
if (snap.hasError && onError != null) {
onError(snap.snapError!.error, snap.snapError!.refresher);
return;
}
if (snap.hasData && onData != null) {
onData(snap.data as T);
return;
}
orElse(snap.data as T);
},
);
}