future property
Future<T> ?
get
future
The Future currently being listened to.
Implementation
Future<T>? get future => _future;
set
future
(Future<T> ? future)
Sets the Future for this AsyncNotifier, updating its state.
Stop listening to any existing future and listens to the new one.
- On start: Updates snapshot to 'waiting'.
- On completion: Updates snapshot with done state and data.
- On error: Updates snapshot with error.
No action is taken if the new future is identical to the current one.\
Example:
final _user = AsyncNotifier<User>();
_user.future = someUserFuture;
Implementation
set future(Future<T>? future) {
if (_future == future) return;
if (future == null) return cancel();
_unsubscribe();
_future = future;
value = snapshot.inState(ConnectionState.waiting);
_future?.then(
(data) {
if (_future != future) return;
value = AsyncSnapshot.withData(ConnectionState.done, data);
onData(data);
onDone();
},
onError: (Object e, StackTrace s) {
if (_future != future) return;
value = AsyncSnapshot.withError(ConnectionState.done, e, s);
onError(e, s);
onDone();
},
);
}