whenConnectionState<R> method Null safety

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