watchFuture<T extends Object, R> method
awaits the Future
returned by select
and triggers a rebuild as soon
as the Future
completes. After that it returns
an AsyncSnapshot
with the received data from the Future
When you call watchFuture a second time on the same Future
it will
return the last received data but not observe the Future a another time.
To be able to use watchStream inside a build
function
we have to pass initialValue
so that it can return something before
the Future
has completed
if select
returns a different Future
than on the last call, watchFuture
will ignore the completion of the previous Future and observe the completion
of the new Future.
preserveState
determines then if the new initial value should be the last
value of the previous stream or again initialValue
Implementation
AsyncSnapshot<R?> watchFuture<T extends Object, R>(
Future<R> Function(T) select,
R initialValue, {
String? instanceName,
bool preserveState = true,
}) =>
widget._state.value.registerFutureHandler<T, R>(select,
initialValueProvider: () => initialValue,
instanceName: instanceName,
preserveState: preserveState,
allowMultipleSubscribers: false);