【问题标题】:Expected a value of type "imageProvider<object>",but got one of type'_HashSet<AssetImage>'>'预期类型为“imageProvider<object>”的值,但得到类型“_HashSet<AssetImage>'>”之一
【发布时间】:2021-08-19 08:11:46
【问题描述】:

我想制作动态课程以使用 for 循环广告获取变量长度来实现这一点

      height: 200.0,
      child: new Carousel(
        boxFit: BoxFit.cover,
//Start problem Area
        images: [
          for (int i = 0; i < widget.eoprod_slider.length; i++)
            {AssetImage(widget.eoprod_slider[i])}
        ],//End Problem Area
        autoplay: false,
        dotSize: 4.0,
        indicatorBgPadding: 2.0,
      ),
    );

【问题讨论】:

    标签: flutter


    【解决方案1】:

    将它们映射成一个列表并按原样传递:

          height: 200.0,
          child: new Carousel(
            boxFit: BoxFit.cover,
            //Start problem Area
            images: widget.eoprod_slider.map((e)=>AssetImage(e)).toList(),
            //End Problem Area
            autoplay: false,
            animationCurve: Curves.fastOutSlowIn,
            animationDuration: Duration(milliseconds: 1000),
            dotSize: 4.0,
            indicatorBgPadding: 2.0,
          ),
        );
    

    【讨论】:

    • 谢谢哥们,它有效 |但我想通过 for 循环知道同样的事情是不可能的
    • 如果解决了您的问题,请将其标记为正确答案,谢谢。可以使用 for 循环,但您必须在构建方法之外创建列表。语法问题 l.
    猜你喜欢
    • 2022-10-07
    • 2022-10-14
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2022-01-26
    • 2021-06-22
    相关资源
    最近更新 更多