我有這個資產影像代碼
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)
uj5u.com熱心網友回復:
您宣告的串列是一種List<Image>型別,但您正在使用它,就好像它是一個List<String>.
試試這個:
final List<String> imagePaths = [
'your/path/pic1.jpg',
'your/path/pic2.jpg',
];
Image.asset(
toolImage[1],
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/457132.html
上一篇:C 中的二分查找實作
下一篇:AppBar下實作TabBar
