refreshableFuture<T> method

(AsyncValue<T>, Future<T> Function()) refreshableFuture<T>(
  1. Future<T> futureFactory()
)

A side effect that allows you to watch a future that can be refreshed by invoking the supplied callback (which will also give you an updated copy of that future).

You supply a futureFactory, which is a function that must return a new instance of a future to be watched.

See also invalidatableFuture, which enables lazy future invalidation.

Internally creates the future to watch on the first build and then again whenever the returned callback is invoked.

Implementation

(AsyncValue<T>, Future<T> Function()) refreshableFuture<T>(
  Future<T> Function() futureFactory,
) {
  final future = use.lazyData(futureFactory);
  final futureState = use.future(future.value);
  return (futureState, () => future.value = futureFactory());
}