Ad

Reduce Flutter Carousel Slider Padding

- 1 answer

I'm using carousel_slider flutter plugin. I want to reduce the space between 'items' widgets. Here's my code:

CarouselSlider(
          options: CarouselOptions(
            enableInfiniteScroll: false,
            initialPage: 0,
            height: screenHeight * 0.35,
            enlargeCenterPage: true,
            viewportFraction: 0.85
          ),
          items: <Widget>[
            Container(
              padding: EdgeInsets.all(0),
              color: Colors.blue,
            ),
            Container(
              padding: EdgeInsets.all(0),
              color: Colors.blue,
            )
          ],
        )

and this is what I'm getting:

output

Ad

Answer

If you want your items to fill all screen width, you should set viewportFraction to 1 :

viewportFraction: 1,  

If you want to keep a lower ratio and remove space between items, the default CarouselOptions() seems to achieve that.

It seems that your parameter that differs from defaults is enlargeCenterPage: true, you might want to keep it false.

I recommend to have a look at the examples here.

Ad
source: stackoverflow.com
Ad