刷卡器未附加到任何滚动视图

问题描述 投票:1回答:1

我写了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,
              );
flutter swiper
1个回答
0
投票

只需删除index: 0,它就可以工作。

背景信息:传递index值会导致错误,并且看起来像是在名为transformer_page_view的swiper依赖库中引起的,或者是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, /* ... */
  );

安装了滑动器后,您可以使用动画更改索引:

  _controller.move(newIndex);
© www.soinside.com 2019 - 2024. All rights reserved.