I created a list and add image path, and now i want to use this list and display the image in gridview, here what i'm doing
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: [])),
but it gives me this error
type 'Image' is not a subtype of type 'String'
please let me know how to do this
CodePudding user response:
Try writing your image widget like this
Image(image: AssetImage(imageList[index]));