ResultNotifier<T>.future constructor
- FetchAsync<
T> fetch, { - T? data,
- Result<
T> ? result, - Duration? expiration,
- ResultNotifierCallback<
T> ? onReset, - T onErrorReturn(
- Object? error
- bool autoReset = false,
- bool refreshOnError = false,
Creates a FutureNotifier that fetches data asynchronously, when needed.
Data is fetched using the provided fetch
function, which can either return a Future that completes data,
or return the data directly (synchronously). Any errors will be caught and converted to Error states.
If expiration
(i.e. cache expiration) is specified, the data will be considered stale after the specified
duration has elapsed since the last update, meaning isFresh will return false.
Optionally provide callbacks for onFetch
and onReset
, which are called when fetch (refresh) or reset
(and also cancellation and disposal) occurs.
If onErrorReturn
is specified, the specified value will be returned as data when an error occurs, meaning this
ResultNotifier will never be able to enter the Error state.
If autoReset
(willAutoReset) is true, this notifier will automatically reset itself when all listeners are
removed.
If refreshOnError
(willRefreshOnError) is true, the refresh method will fetch new data when the current
state is Error.
Implementation
factory ResultNotifier.future(
FetchAsync<T> fetch, {
T? data,
Result<T>? result,
Duration? expiration,
ResultNotifierCallback<T>? onReset,
T Function(Object? error)? onErrorReturn,
bool autoReset = false,
bool refreshOnError = false,
}) {
return FutureNotifier<T>(
fetch,
data: data,
result: result,
expiration: expiration,
onReset: onReset,
onErrorReturn: onErrorReturn,
autoReset: autoReset,
refreshOnError: refreshOnError,
);
}