StockResponseExtensions<T> extension

Useful StockResponse extensions.

on

Properties

isData bool
Returns if the response is a StockResponseData
no setter
isError bool
Returns if the response is a StockResponseError
no setter
isLoading bool
Returns if the response is a StockResponseLoading
no setter

Methods

getDataOrNull() → T?
If there is data available, returns it; otherwise returns null.
map<E>({required E onLoading(StockResponseLoading<T> value), required E onData(StockResponseData<T> value), required E onError(StockResponseError<T> value)}) → E
Invokes onData if the response is successful, onLoading if the response is loading, and onError if the response is an error.
mapData<E>(E onData(StockResponseData<T> value)) StockResponse<E>
Invokes onData to transform the StockResponse
mapOrNull<E>({E onLoading(StockResponseLoading<T> value)?, E onData(StockResponseData<T> value)?, E onError(StockResponseError<T> value)?}) → E?
Invokes onData if the response is successful, onLoading if the response is loading, and onError if the response is an error. If the callback is not provided, null is returned.
maybeMap<E>({required E orElse(), E onLoading(StockResponseLoading<T> value)?, E onData(StockResponseData<T> value)?, E onError(StockResponseError<T> value)?}) → E
Invokes onData or orElse as fallback if the response is successful, onLoading or orElse as fallback if the response is loading, and onError or orElse as fallback if the response is an error.
maybeWhen<E>({required E orElse(ResponseOrigin origin), E onLoading(ResponseOrigin origin)?, E onData(ResponseOrigin origin, T data)?, E onError(ResponseOrigin origin, Object error, StackTrace? stackTrace)?}) → E
Invokes onData or orElse as fallback if the response is successful, onLoading or orElse as fallback if the response is loading, and onError or orElse as fallback if the response is an error.
requireData() → T
Returns the available data or throws error if there is no data.
requireError() Object
Returns the available data or throws error if there is no data.
throwIfError() → void
If this StockResponse is of type StockResponseError, throws the exception. Otherwise, does nothing.
when<E>({required E onLoading(ResponseOrigin origin), required E onData(ResponseOrigin origin, T data), required E onError(ResponseOrigin origin, Object error, StackTrace? stackTrace)}) → E
Invokes onData if the response is successful, onLoading if the response is loading, and onError if the response is an error.
whenOrNull<E>({E onLoading(ResponseOrigin origin)?, E onData(ResponseOrigin origin, T data)?, E onError(ResponseOrigin origin, Object error, StackTrace? stackTrace)?}) → E?
Invokes onData if the response is successful, onLoading if the response is loading, and onError if the response is an error. If the callback is not provided, null is returned.