'Unable to load asset: Image
I have this code for asset image
Image.asset(
'${listPic[1]}',
),
the images are located in a Listfinal List<Image> listPic= <Image>[ Image.asset('assets/images/pic1.jpg'), Image.asset('assets/images/pic2.jpg'), ];
I know the pubsec works, because when I directly type the image location like this
Image.asset(
'assets/images/pic1.jpg',
),
the image is displayed, Is there something wrong with the list or Image.asset() I have tried using .toString after the ${listPic[0]} it didn't do anything instead said unnecessary string interpolation.
gives this error
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)
Solution 1:[1]
The list you declared is a List<Image> type, but you are using it as if it's a List<String>.
Try this instead:
final List<String> imagePaths = [
'your/path/pic1.jpg',
'your/path/pic2.jpg',
];
Image.asset(
toolImage[1],
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
