Search code examples
apifluttercarousel

How to set image from API to Carousel in Flutter


I want to use a Banner Slider in Flutter apps, so I found a library to make it, namely Carousel. This is a good library but I found a problem for this library, How to set image from API into Carousel? or have any library for support image from API (list), have dot indicator, autoplay like Carousel?


Solution

  • Use Carousel package -: carousel_slider: ^1.3.0

        CarouselSlider(
              autoPlay: true,
              pauseAutoPlayOnTouch: Duration(seconds: 5),
              height: MediaQuery.of(context).size.height * 0.60,
              items: <Widget>[
                for (var i = 0; i < image.length; i++)
                  Container(
                      margin: const EdgeInsets.only(top: 20.0, left: 20.0),
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: NetworkImage(image[i]),
                          fit: BoxFit.fitHeight,
                        ),
                        // border:
                        //     Border.all(color: Theme.of(context).accentColor),
                        borderRadius: BorderRadius.circular(32.0),
                      ),
                    ),                                     
              ],
            ),