maybeMap<E> method

E maybeMap<E>({
  1. AsyncDataBuilder<E, T>? data,
  2. AsyncErrorBuilder<E>? error,
  3. AsyncStateBuilder<E>? loading,
  4. AsyncStateBuilder<E>? reloading,
  5. AsyncStateBuilder<E>? refreshing,
  6. required AsyncStateBuilder<E> orElse,
})

Map the state to a value with optional or else.

final signal = StreamSignal<int>();
signal.value.maybeMap(
 data: (value) => 'Value: $value',
 orElse: () => 'Loading...',
);

Implementation

E maybeMap<E>({
  AsyncDataBuilder<E, T>? data,
  AsyncErrorBuilder<E>? error,
  AsyncStateBuilder<E>? loading,
  AsyncStateBuilder<E>? reloading,
  AsyncStateBuilder<E>? refreshing,
  required AsyncStateBuilder<E> orElse,
}) {
  if (isRefreshing) if (refreshing != null) return refreshing();
  if (isReloading) if (reloading != null) return reloading();
  if (hasValue) if (data != null) return data(value as T);
  if (hasError) if (error != null) return error(this.error!, stackTrace);
  if (loading != null) return loading();
  return orElse();
}