whenConnectionState<R> method

R whenConnectionState<R>({
  1. required R onIdle(),
  2. required R onWaiting(),
  3. required R onData(
    1. T snapState
    ),
  4. required R onError(
    1. dynamic error
    ),
  5. 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);
}