flutter - 滚动控制器未附加到任何滚动视图(Swiper)
问题描述
我正在使用一个Swiper
包来在我的图像上实现轮播效果。我试图Swiper
通过将callback
函数传递给它的孩子来更新我的当前索引。
但是当我尝试调用该函数时,它会返回此“ scrollcontroller not attached
”错误。
我添加了一个SwiperController
但仍然相同。
这是我的代码:
SwiperController swiperController;
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.black,
child: Swiper(
controller: swiperController,
index: _index,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext c, int i) {
return StoriesPerUser(
storiesList: widget.storiesList,
selectedIndex: i,
updateFunction: callBack,
);
},
itemCount: widget.storiesList.length,
loop: false,
duration: 1000,
));
}
callBack() {
setState(() {
_index++;
});
}
Please help.
解决方案
答案:
如果你们中的任何一个人想要使用这个包,并且如果你想要一个类似于我的功能,而不是更新索引,只需使用其中一种方法SwiperController
是next()
.
这解决了我的问题:
callBack() {
setState(() {
swiperController.next();
});
}
推荐阅读
- java - 简单的 Spring @CreatedDate 注释对我不起作用
- objective-c - 无效的内存引用(SIGSEGV)和类错误的不完整实现
- ubuntu - gasLimit 随时间减少
- ios - React-Native 调试工具/开发者菜单在 iOS 设备上不起作用
- python - 删除区分大小写的停用词
- python - 如何在没有双引号的情况下修复 JSON 键值?
- angular - Angular router.url - 传递 id
- javascript - HtmlWebpackPlugin 插件不输出任何东西
- mongodb - 更新路径“x”会在“x”处产生冲突
- python - 并排绘制两个 seaborn 热图