Home > Net >  How to Display Particulate range of image from list in CarouselSlider.builder in Flutter?
How to Display Particulate range of image from list in CarouselSlider.builder in Flutter?

Time:02-10

I want to display Images from list in CarouselSlider.builder from index 1 to 3.

Here as below I got all Data from Api in _imageList.

List<ImageModel> _imageList = [];

@override
  void initState() {
    super.initState();
    ApiHelper().getImageList().then((images) {
      setState(() {
        _imageList = images;
      });
    });
  }

Here is my Image Slider Code as below.

CarouselSlider.builder(
                              itemCount: _imageList.length,
                              itemBuilder:
                                  (BuildContext context, int index, realindex) {
                                return Image.network(
                                  "$imageUrl"   _imageList[index].imgPath!,
                                  width: MediaQuery.of(context).size.width - 40,
                                  fit: BoxFit.fill,
                                );
                              },
                              options: CarouselOptions(
                                viewportFraction: 1,
                                enlargeCenterPage: true,
                                initialPage: 1,
                              ),
                            ),

So how can i do this? Thank you.

CodePudding user response:

in your initState method you can just create a sublist of the images list so your imageList only contains the indices 1-3.

_imageList = images.sublist(1, 4);
  • Related