首页 > 解决方案 > 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,
              );

标签: flutterswiper

解决方案


只需删除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);

推荐阅读