Home > Software engineering >  How to show image slider in flutter?
How to show image slider in flutter?

Time:12-04

I have a list of image url named Src. I want to show these images by this package:https://pub.dev/packages/flutter_image_slideshow . but when do it like this:

Container(
      width: pageWidth,
      height: pageHeight / 2.5,
      // color: Colors.red,
      child: ImageSlideshow(
        children: [
          CachedNetworkImage(
            imageUrl: src,
          ),
        ],
      )
    );

console says:

type 'List<String>' is not a subtype of type 'String'

also when i convert my list to String like this:

CachedNetworkImage(
            imageUrl: src.toString().replaceAll("[", "").replaceAll("]", ""),
          ),

console says:

I/flutter ( 4859): CacheManager: Failed to download file from https://ahmadihypermarket.com/ext/uploads/2021/11/1-378.jpg, https://ahmadihypermarket.com/ext/uploads/2021/11/2-290.jpg with error:
I/flutter ( 4859): HttpException: Invalid statusCode: 404, uri = https://ahmadihypermarket.com/ext/uploads/2021/11/1-378.jpg, https://ahmadihypermarket.com/ext/uploads/2021/11/2-290.jpg

does anybody know how to fix it and show the images?

CodePudding user response:

Try with the below code

Container(
      width: pageWidth,
      height: pageHeight / 2.5,
      // color: Colors.red,
      child: ImageSlideshow(
        children:List<Widget>.generate(
                  src.length,
                  (index) {
                    return CachedNetworkImage(
                          imageUrl: src[index],
                       );
                  },
                ), 
      )
    );
  • Related