invoke method

  1. @protected
void invoke({
  1. bool resetOnBefore = true,
})

发起请求

Implementation

@protected
void invoke({bool resetOnBefore = true}) {
  if (resetOnBefore) {
    _setValue(AsyncSnapshot<TValue>.nothing());
  }

  var future = _futureGetter();
  _onStart?.call();
  final callbackIdentity = Object();
  _callbackIdentity = callbackIdentity;
  future.then<void>((TValue data) {
    if (_callbackIdentity == callbackIdentity) {
      var _data = _handle == null ? data : _handle!(data);
      _onSuccess?.call(_data);
      _setValue(AsyncSnapshot<TValue>.withData(ConnectionState.done, _data));
    }
    _onEnd?.call();
  }, onError: (Object error) {
    if (_callbackIdentity == callbackIdentity) {
      _setValue(AsyncSnapshot<TValue>.withError(ConnectionState.done, error));
      _onError?.call(error);
    }
    _onEnd?.call();
  });
  _setValue(value.inState(ConnectionState.waiting));
}