flutter - Swiper 未附加到任何滚动视图
问题描述
我写了 swiper。而且我的异常 ScrollController 没有附加到任何滚动视图。我不知道如何解决这个问题。
返回刷卡者(
loop: true,
autoplay: false,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return _itemList(snapshot.data[index], context, index);
},
viewportFraction: 0.8,
scale: 0.7
index: 0,
);
解决方案
只需删除index: 0
它应该可以工作。
背景信息:传递一个index
值会导致错误,看起来它是由调用的 swiper 的依赖库transformer_page_view
或 swiper 中的错误实现引起的。
由于我也遇到了同样的问题,在网上没有找到任何解决方案,我将分享我的代码如何设置初始index
值:
final _controller = SwiperController();
// "animation: false" does the trick
// "index" is the initial value when the swiper is shown
_controller.move(index, animation: false);
// ...
return Swiper(
controller: _controller, /* ... */
);
安装 swiper 后,您可以使用动画更改索引:
_controller.move(newIndex);
推荐阅读
- javascript - 在 Chrome 控制台中,如何打印输入的数据?
- xamarin - Listview 在 xamarin 表单中从下到上滚动滞后问题
- android - 如何将 google play 开发者帐户转移到另一个 google 帐户?
- reactjs - 如何将 React 函数中的参数从一个文件传递到另一个文件
- abap - 将两个内部表连接并聚合为一张
- azure - Xamarin Android 构建在 AppCenter (Azure) 中失败并出现错误 APT0000
- python - 分组数据处理后向数据框中添加新列时出错
- excel - vba excel中是否有选择要出现的excel窗口的代码?
- apache - 如何使用 Apache 在生产环境中运行 Mercure
- arrays - 从选择表单中保存数组值而不是索引