when<T> abstract method

T when<T>({
  1. required T loading(),
  2. required T data(
    1. S data
    ),
  3. required T error(
    1. ErrorState e
    ),
})

Pattern matching for async state.

loading is called if the state is loading. data is called if the state contains data. error is called if the state contains an error.

Returns the result of the matching callback. All callbacks are required and must be provided.

Implementation

T when<T>({
  required T Function() loading,
  required T Function(S data) data,
  required T Function(ErrorState e) error,
});