maybeMap<E> method
E
maybeMap<E>({
- AsyncDataBuilder<
E, T> ? data, - AsyncErrorBuilder<
E> ? error, - AsyncStateBuilder<
E> ? loading, - AsyncStateBuilder<
E> ? reloading, - AsyncStateBuilder<
E> ? refreshing, - 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();
}