flutter_swiper:Another exception was thrown: ScrollController attached to multiple scroll views.
2021/9/13 6:06:58
本文主要是介绍flutter_swiper:Another exception was thrown: ScrollController attached to multiple scroll views.,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Another exception was thrown: ScrollController attached to multiple scroll views.
翻译一下:引发了另一个异常:ScrollController连接到多个滚动视图。
Flutter Swiper是一个轮播图组件,内部包含一个Widget List,当这个Widget List数量大于1,就可能会有这种情况
解决方案:给Swiper加一个Key即可解决
原有代码
return Container( child: AspectRatio( aspectRatio: 1.5 / 1, // 宽高比450/300 child: Swiper( itemBuilder: (BuildContext context, int index) { return new Image.network( imgList[index]['url'], fit: BoxFit.fill, ); }, itemCount: imgList.length, pagination: new SwiperPagination(), control: new SwiperControl(), autoplay: true, ), ), );
更新代码
return Container( child: AspectRatio( aspectRatio: 1.5 / 1, // 宽高比450/300 child: Swiper( key: UniqueKey(), // 这个必须添加,代表唯一 itemBuilder: (BuildContext context, int index) { return new Image.network( imgList[index]['url'], fit: BoxFit.fill, ); }, itemCount: imgList.length, pagination: new SwiperPagination(), control: new SwiperControl(), autoplay: true, ), ), );
大功告成!!
这篇关于flutter_swiper:Another exception was thrown: ScrollController attached to multiple scroll views.的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Rocket消息中间件教程:新手入门详解
- 2024-11-26RocketMQ项目开发教程:新手入门指南
- 2024-11-26MQ源码教程:轻松入门Apache MQ源码解析
- 2024-11-26Rocket消息队列教程:新手入门必读
- 2024-11-26Rocket消息队列教程:新手入门指南
- 2024-11-26RocketMQ底层原理教程:新手入门指南
- 2024-11-26RocketMQ底层原理教程:入门级详解
- 2024-11-26如何获取 OpenAI API Key 用于ChatGPT AI大模型开发?
- 2024-11-26MATLAB 中 A(7)=[];什么意思?-icode9专业技术文章分享
- 2024-11-26UniApp 中如何实现使用输入法时保持页面列表不动的效果?-icode9专业技术文章分享