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
2
3
4
5
|
if (_scrollController.position.pixels == 0 && prePixels != 0) {
_scrollController.jumpTo(prePixels);
prePixels = _scrollController.position.pixels;
|
我使用了上面的代码,(向上滑动后这部分UI不显示了,所以flutter就不渲染了,
_scrollController
也就不存在了),所以报错了。
解决方案是加一个判断,等向上滑动后UI不显示了,就不执行这部分代码就好了
上面那个网站给出了是 if (_scrollController.hasClients){}
if (_scrollController.hasClients) {
if (_scrollController.position.pixels == 0 && prePixels != 0) {
_scrollController.jumpTo(prePixels);
prePixels = _scrollController.position.pixels;
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/scrol
昨天从其他页面回到首页,滑动banner图切换时发现一个错误,虽然没有导致崩溃,但是总是觉得不舒服:
Unhandled Exception: 'package:flutter/src/widgets/scroll_controller.dart':
Failed assertion: line 110 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views.
#0 _Assertion
Flutter Swiper是一个轮播图组件,内部包含一个Widget List,当这个Widget List数量发生变化的时候如果出现类似这种异常情况导致轮播图不滑动或者其他红屏等错误,
I/flutter (15202): ScrollController not attached to any scroll views.
I/flutter (15202): 'package:flutt...
在Flutter中使用
ScrollView滑动组件,如SingleChild
ScrollView,可通过
ScrollController来监听滑动,通常会通过
ScrollController 来获取滑动的距离等,当
ScrollController 与对应的滑动组件未绑定成功时,调用如获取滑动位置的方法
double offset = _
scrollController.offset;
会抛出
ScrollController not
attached to any
scroll views 异常
报错如下:
ScrollController not
attached to any
scroll views.
‘package:flutter/src/widgets/
scroll_
controller.dart’:
Failed assertion: line 112 pos 12: ‘_
positions.
isNotEmpty’
报错位置:就是Swiper插件这,突然就报这样的错啦,导致点击操作也没办发
解决方法:在相关位置加key:GlobalKey(),如下:
Flutter 解决在使用Swiper过程中出现
ScrollController not
attached to any
scroll views.异常
给轮播图添加一个key就不会出现这个问题了
key: UniqueKey(),
具体的原因可以参考这篇博文,理解key值在flutter渲染刷新时候的作用 https://www.jianshu.com/p/6e704112dc67
Flutter和Dart系列文章和代码GitHub地址
在Flutter中, 当内容超过显示视图时,如果没有特殊处理,Flutter则会提示Overflow错误
Flutter提供了多种可滚动(Scrollable Widget)用于显示列表和长布局
可滚动Widget都直接或间接包含一个Scrollable, 下面是常用的几个可滚动的Widget
SingleChildScrollVie...
轮播图数量变化导致问题异常信息:
Failed assertion: line 112 pos 12: '_
positions.
isNotEmpty':
ScrollController
ScrollController not
attached to any
scroll views.
'package:flutter/src/widgets/
scroll_
controller.dart':
Failed assertion: line 110 pos 12: '_po
_AssertionError ('package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 108 pos 12: '_positions.length == 1': ScrollController attached to multiple scroll views.)
koxyoxyo:
HTML5+ plus.maps地图定位,标记多个自定义mark及mark点击(附官方文档链接)
ʚ崔恒ɞ:
android 发送邮件(带附件)
Jason572057:
Android基本动画加速器
qq_43479892: