【问题标题】:How to display images from list in flutter如何在颤动中显示列表中的图像
【发布时间】:2021-12-17 20:26:20
【问题描述】:

我创建了一个列表并添加了图像路径,现在我想使用这个列表并在 gridview 中显示图像,这就是我在做什么

List imageList=["assets/img/pepsi2.jpg","assets/img/pepsi2.jpg"];



imageList.length!=0? GridView.builder(
                shrinkWrap:true,
                itemCount: imageList.length,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount:2, ),
                 itemBuilder: (BuildContext context,int index){
                   return Padding(
                     padding: const EdgeInsets.all(8.0),
                     child: Stack(
                       children:[
                         ClipRRect(
                              borderRadius: BorderRadius.circular(10.0),
                              child: Image.asset(imageList[index],
                                width: MediaQuery.of(context).size.width * 0.35,
                                height: MediaQuery.of(context).size.height * 0.17,
                                fit: BoxFit.cover,
                              ),
                            ),
                         Align(
                          alignment: Alignment.topRight,
                          child: buildCancelIcon(
                            color,
                            () {
                              setState(() {
                               _imageFileList!.removeAt(index);
                              });
                            },
                            Icons.cancel

                          ))] 
                     ),
                   );
                 }):Padding(
          padding: const EdgeInsets.only(left: 70),
          child:
              Row(crossAxisAlignment: CrossAxisAlignment.center, children: [])),

但它给了我这个错误

type 'Image' is not a subtype of type 'String'

请告诉我怎么做

【问题讨论】:

  • 错误发生在哪一行?

标签: list image flutter


【解决方案1】:

尝试像这样编写图像小部件

Image(image: AssetImage(imageList[index]));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    相关资源
    最近更新 更多