ResultNotifier<T> constructor

ResultNotifier<T>({
  1. T? data,
  2. Result<T>? result,
  3. Duration? expiration,
  4. ResultNotifierCallback<T>? onFetch,
  5. ResultNotifierCallback<T>? onReset,
  6. T onErrorReturn(
    1. Object? error
    )?,
  7. bool autoReset = false,
  8. bool refreshOnError = false,
})

Starts with the specified data (represented as Data), result, or otherwise the Initial loading state.

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

ResultNotifier({
  T? data,
  Result<T>? result,
  this.expiration,
  this.onFetch,
  this.onReset,
  this.onErrorReturn,
  bool autoReset = false,
  bool refreshOnError = false,
})  : willAutoReset = autoReset,
      willRefreshOnError = refreshOnError,
      _value = data != null ? Data(data) : result ?? Initial<T>();