Unhandled Exception: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 110 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views.
这个问题试了很多方法
终于在这个网站https://stackoverflow.com/questions/52296387/scrollcontroller-jumpto-scrollcontroller-not-attached-to-any-scroll-views看到解决的要点
问题是出在
1 【_positions.isNotEmpty: ScrollController not attached to any scroll views.】2 3 4 5 |
|
_scrollController
也就不存在了),所以报错了。解决方案是加一个判断,等向上滑动后UI不显示了,就不执行这部分代码就好了
上面那个网站给出了是 if (_scrollController.hasClients){}
增加后
if (_scrollController.hasClients) {
if (_scrollController.position.pixels == 0 && prePixels != 0) {
_scrollController.jumpTo(prePixels);
}
prePixels = _scrollController.position.pixels;
}
推荐阅读
- 回顾 Flutter 2021 重要时刻,奉上虎年红包封面喜迎新年!
- Flutter实现左侧边栏导航
- 如何在 Flutter 创建一个后台任务
- Flutter Convex Bottom 底部导航
- Flutter动态化框架Thresh
- 基于 Riverpod 的 Flutter 状态管理
- Flutter 2022 产品路线图发布
- Flutter 插件库
- Windows Running “flutter pub get“ in XXX卡死
- Flutter之下拉刷新,上拉加载更多