setFutureValue method

  1. @protected
Future<void> setFutureValue(
  1. WhenFuture<T> whenFuture,
  2. FutureSnapshotListenerCallback<T>? listener,
  3. VoidCallback? onFinally
)

Sets a value after an asynchronous computation that returned a future

Implementation

@protected
Future<void> setFutureValue(
  WhenFuture<T> whenFuture,
  FutureSnapshotListenerCallback<T>? listener,
  VoidCallback? onFinally,
) {
  final Object callbackIdentity = Object();
  _activeCallbackIdentity = callbackIdentity;

  return whenFuture.refreshSnapshots(
    (snapshot) {
      if (_activeCallbackIdentity != callbackIdentity) return;

      listener?.call(snapshot as FutureSnapshot<T>);
      _updateSnapshot(snapshot as FutureSnapshot<T>);
    },
    () {
      if (_activeCallbackIdentity != callbackIdentity) return;

      onFinally?.call();
    },
  );
}