[在使用CarouselSlider软件包时出现错误,它显示错误类型'Image'不是flutter中'String'类型的子类型

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

它显示来自网络的url图像,但不显示来自assts的图像,因为我正在尝试访问assers的图像。

从我的flutter项目中获取的图像列表:

int _current = 0;
  final List imgList = [
    Image.asset('assests/GL.png'),
    Image.asset('assests/GL.png'),
    Image.asset('assests/GL.png'),
     ];

CarouselSlider中的代码


CarouselSlider(
                  height: 200,
                  initialPage: 0,
                  enlargeCenterPage: true,
                  autoPlay: true,
                  reverse: false,
                  enableInfiniteScroll: true,
                  autoPlayInterval: Duration(seconds: 3),
                  autoPlayAnimationDuration: Duration(milliseconds: 2000),
                  pauseAutoPlayOnTouch: Duration(seconds: 10),
                  scrollDirection: Axis.horizontal,
                  onPageChanged: (index){
                    setState(() {
                      _current = index;
                    });
                  },


                  items: imgList.map((imgUrl){

                    return Builder(
                    builder: (BuildContext context){
                      return Container(
                      width: MediaQuery.of(context).size.width,
                        margin: EdgeInsets.symmetric(horizontal: 10.0),
                          decoration: BoxDecoration(color: Colors.green),
                        child: Image.assest(imgUrl,fit:BoxFit.fill),//error line in code
                      );
                      },
                    );

                }).toList(),),
            SizedBox(height: 20,),
              ],
            ),
        ),
flutter dart carousel
1个回答
0
投票

您必须在列表中设置网址,而不是图像小部件。将您的列表更改为:

final List imgList = [
    'assests/GL.png',
    'assests/GL.png',
    'assests/GL.png',
];
© www.soinside.com 2019 - 2024. All rights reserved.