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

当hitOver和infiniteHitOver为true时,加载更多内容后无法停止回弹动画 #831

Open
hao-feng opened this issue May 24, 2024 · 4 comments

Comments

@hao-feng
Copy link

使用example项目,
修改nested_scroll_view.dart 中的header和footer
hitOver: true, infiniteHitOver: true
模拟比较快的请求,修改 Future.delayed(const Duration(milliseconds: 300)
滑动列表到底部,在回弹的过程中,加载的请求返回了,单列表仍然在继续执行回弹动画
附件为修改后的nested_scroll_view.dart
nested_scroll_view.dart.zip

bug效果如下

RPReplay_Final1716535593.MP4
@xuelongqy
Copy link
Owner

设计如此吧。回弹动画是Flutter自身的,打断也会很奇怪。几种解决办法,1.设置infiniteOffset,在没有滑到底部就加载;2.不设置infiniteHitOver和hitOver;3.增加异步延时。倾向于第二种方法,因为这个回弹并不会提升用户体验,其次呢一定要去解决这个问题,纯属于开发者内耗,没有必要的。

@hao-feng
Copy link
Author

怎么会是设计如此呢,随便找一个 ios app 的回弹都不会是这样的,都是会打断回弹并且往相反方向滚动(如果还有速度的话)
我来翻译一下上边的解决方案:1和 3 都是降低了触发问题的概率,一个是说到底部之前就完成请求,一个是说尽量等回弹结束了再完成请求🥹
2 的意思是说别用 ios 的列表滚动效果了

@xuelongqy
Copy link
Owner

是的,在我看来无限滚动没必要使用ios的回弹效果,所以默认到底部是无法越界的。如果你在Flutter中找到在非用户事件的情况下能够判断列表变化,并能阻止滚动的方法,请告诉我,或者提交pr。短时间内,我没有时间去研究这个。

@hao-feng
Copy link
Author

hao-feng commented Jun 5, 2024

extension ExtensionScrollController on ScrollController {
  void stopScrollingIfBouncing() {
    const double footerHeight = 50;
    if (position.pixels - footerHeight > position.maxScrollExtent) {
      // 获取当前的滚动位置
      final double currentScrollPosition = position.pixels;
      // 向下滚动
      animateTo(currentScrollPosition + 1,
          duration:
              Duration(milliseconds: 1),
          curve: Curves.decelerate);
    }
  }
}

如果有其他人遇到类似问题的话,我临时的解决方案是在scrollview高度变化时调用如上方法,可以打断当前的回弹动画,并继续正常的向下滚动滑动

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