无法加载资产:图片

Unable to load asset: Image

我有资产图片的代码

 Image.asset(
              '${listPic[1]}',
           
            ),

图像位于列表中
final List<Image> listPic= <Image>[ Image.asset('assets/images/pic1.jpg'), Image.asset('assets/images/pic2.jpg'), ];

我知道 pubsec 有效,因为当我像这样直接输入图像位置时

Image.asset(
              'assets/images/pic1.jpg',
            ),

显示图像, 列表或 Image.asset() 有问题吗 我试过在 ${listPic[0]} 之后使用 .toString 它没有做任何事情而是说不必要的字符串插值。

出现这个错误

The following assertion was thrown resolving an image codec: Unable to load asset: Image(image: AssetImage(bundle: null, name: "assets/images/pic1.jpg"), frameBuilder: null, loadingBuilder: null, alignment: Alignment.center, this.excludeFromSemantics: false, filterQuality: low)

您声明的列表是 List<Image> 类型,但您将其用作 List<String>

试试这个:

final List<String> imagePaths = [ 
    'your/path/pic1.jpg', 
    'your/path/pic2.jpg',
];

Image.asset(
    toolImage[1],
)