whenOrNull<R> method
R?
whenOrNull<R>({
- bool skipLoading = false,
- R data(
- T data
- R error(
- Object error,
- StackTrace stackTrace
- R loading()?,
- R none()?,
Allows you to define custom behavior for different states of an AsyncSnapshot
by providing callbacks for data, error, loading, and none.
Same as when but returns null for unhandled states.
Implementation
R? whenOrNull<R>({
bool skipLoading = false,
R Function(T data)? data,
R Function(Object error, StackTrace stackTrace)? error,
R Function()? loading,
R Function()? none,
}) {
return when(
skipLoading: skipLoading,
data: data ?? (_) => null,
error: error ?? (_, __) => null,
loading: loading ?? () => null,
none: none ?? () => null,
);
}