Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_onCanProcess空指针异常 #782

Closed
wanggaowan opened this issue Nov 9, 2023 · 1 comment
Closed

_onCanProcess空指针异常 #782

wanggaowan opened this issue Nov 9, 2023 · 1 comment

Comments

@wanggaowan
Copy link

_EasyRefreshState initState初始化数据时,Future中_callRefresh是延迟执行的,会存在_callRefresh还未执行时先执行了dispose()。
而_headerNotifier.dispose()会将_onCanProcess置为null,而IndicatorNotifier 中 bool get _canProcess => _onCanProcess!.call();
强制不为null。最终执行_callRefresh报空指针异常

// _EasyRefreshState代码

@override
  void initState() {
    super.initState();
    // Refresh on start.
    if (widget.refreshOnStart && widget.onRefresh != null) {
      _isRefreshOnStart = true;
      Future(() {
        _ambiguate(WidgetsBinding.instance)!.addPostFrameCallback((timeStamp) {
          _callRefresh(
            overOffset: widget.callRefreshOverOffset,
            duration: null,
          );
        });
      });
    }
    _initData();
    widget.controller?._bind(this);
  }

@override
  void dispose() {
    _headerNotifier.dispose();
    _footerNotifier.dispose();
    _userOffsetNotifier.dispose();
    super.dispose();
  }


// _callRefresh最终执行的代码
Future callTask({
    required double overOffset,
    Duration? duration,
    Curve curve = Curves.linear,
    ScrollController? scrollController,
    bool force = false,
  }) {
    if (!force) {
      // 就是!_canProcess空指针异常
      if (modeLocked || noMoreLocked || secondaryLocked || !_canProcess) {
        return Future.value();
      }
    } else {
      _offset = 0;
      _mode = IndicatorMode.inactive;
      _processing = false;
    }
    return animateToOffset(
      offset: actualTriggerOffset + overOffset,
      mode: IndicatorMode.ready,
      duration: duration,
      curve: curve,
      scrollController: scrollController,
    );
  }



// IndicatorNotifier代码

// 强制_onCanProcess不会为null
bool get _canProcess => _onCanProcess!.call();

// 但是dispose里会置为null
@override
  void dispose() {
    _onCanProcess = null;
    _clampingAnimationController?.dispose();
    userOffsetNotifier.removeListener(_onUserOffset);
    _task = null;
    _modeChangeListeners.clear();
    _indicator.listenable?._unbind();
    _mounted = false;
    super.dispose();
  }

image
@xuelongqy
Copy link
Owner

3.3.2+4 已解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants