AsyncSnapshotResultExtension<T> extension

Extension methods on AsyncSnapshot that provide a Result-like API similar to Kotlin and Rust's Result class, but with an additional "pending" state.

on

Methods

expect() → T

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Expects the snapshot to be Ok and returns the value. Throws a StateError if the snapshot is not Ok.
expectErr() → Object

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Expects the snapshot to be an Error and returns the error. Throws a StateError if the snapshot is not an Error.
isErr() → bool

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Checks if the snapshot has an error. Returns true if the snapshot has an error.
isOk() → bool

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Checks if the snapshot has completed successfully (with or without a value). Returns true if the snapshot is done and has no error.
isPending() → bool

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Checks if the snapshot is pending (waiting or none state). Returns true if the snapshot is in waiting or none state.
isUndefined() → bool

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Checks if the snapshot has a null value. Returns true if the snapshot is ok but the data is null.
map<N>(N fn(T)) → AsyncSnapshot<N>

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Transforms the snapshot by applying a function to the Ok value, similar to Iterable.map.
mapErr(Object fn(Object)) → AsyncSnapshot<T>

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Transforms the snapshot by applying a function to the Error value.
mapOrElse<N>({N ok(T)?, N nullValue(T)?, N err(Object)?, N pending()?}) → N?

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Unboxes the snapshot by applying different functions based on the state. This is extremely useful for building UIs!
okOr(T defaultValue, {bool filterNullish = false}) → T

Available on AsyncSnapshot<T>, provided by the AsyncSnapshotResultExtension extension

Gets the Ok value or a default value if the result is not Ok.