whenConnectionState<R> method
R
whenConnectionState<R>({
- required R onIdle(),
- required R onWaiting(),
- required R onData(
- T snapState
- required R onError(
- dynamic error
- bool catchError = true,
Exhaustively switch over all the possible statuses of connectionState. Used mostly to return Widgets.
Implementation
R whenConnectionState<R>({
required R Function() onIdle,
required R Function() onWaiting,
required R Function(T snapState) onData,
required R Function(dynamic error) onError,
bool catchError = true,
}) {
if (isIdle) {
return onIdle.call();
}
if (hasError) {
return onError.call(error);
}
if (isWaiting) {
return onWaiting.call();
}
return onData.call(_state);
}