whenOrNull<U> method

U? whenOrNull<U>(
  1. {U initial(
    1. T?
    )?,
  2. U waiting(
    1. T?
    )?,
  3. U complete(
    1. T
    )?,
  4. U error(
    1. T?,
    2. Object?,
    3. StackTrace?
    )?}
)

A method that returns a value returned from one of callback functions corresponding to the current phase of an asynchronous operation.

This is identical to when except that all properties are optional. It returns null if the callback corresponding to the current phase has not been provided,

Implementation

U? whenOrNull<U>({
  U Function(T?)? initial,
  U Function(T?)? waiting,
  U Function(T)? complete,
  U Function(T?, Object?, StackTrace?)? error,
}) {
  return when(
    initial: initial,
    waiting: (data) => waiting?.call(data),
    complete: (data) => complete?.call(data),
    error: (data, e, s) => error?.call(data, e, s),
  );
}