snapshots method

  1. @override
Future<void> snapshots(
  1. FutureSnapshotListenerCallback<T> listener, [
  2. VoidCallback? onFinally
])
override

Asynchronously executes a computation once with snapshots callbacks in parameters for the asynchronous computation that may fail into something that is safe to read.

This is useful to avoid having to do a tedious try/catch/then.

This is same as execute except that it will return a snapshot of the asynchronous computation's state.

Implementation

@override
Future<void> snapshots(
  FutureSnapshotListenerCallback<T> listener, [
  VoidCallback? onFinally,
]) {
  return execute(
    onLoading: () => listener(FutureSnapshot<T>.loading()),
    onComplete: (it) => listener(FutureSnapshot<T>.complete(it)),
    onError: (e, s) => listener(FutureSnapshot<T>.error(e, s)),
    onFinally: onFinally,
  );
}