zoukankan      html  css  js  c++  java
  • 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,
            ),
          ),
        );
    

    大功告成!!

  • 相关阅读:
    构建之法阅读笔记02
    4.7-4.13 第八周总结
    构建之法阅读笔记01
    顶会热词统计
    结对作业-四则运算升级版
    3.31-4.5 第七周总结
    大道至简阅读笔记03
    3.23-3.30 第六周总结
    第7周总结
    人月神话阅读笔记之三
  • 原文地址:https://www.cnblogs.com/sugartang/p/15260747.html
Copyright © 2011-2022 走看看