then<R> method Null safety

void then<R>(
  1. VoidCallback onValue,
  2. {Function? onError}
)

回调

Implementation

void then<R>(VoidCallback onValue, {Function? onError}) {
  if (isComplete) {
    if (isError && onError != null) {
      onError(error);
    } else
      onValue(result);
  } else {
    if (_callback == null) {
      _callback = [];
    }
    _callback!.add(onValue);
    if (onError != null) {
      if (_onError == null) {
        _onError = [];
      }
      _onError!.add(onError);
    }
  }
}