Reduce Flutter carousel slider padding

5,907

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.

Share:
5,907
Zaeem
Author by

Zaeem

Updated on December 22, 2022

Comments

  • Zaeem
    Zaeem over 1 year

    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

  • Zaeem
    Zaeem almost 4 years
    Thank you for your response. You're right, it was the enlargeCenterPage that was creating a padding around the children widgets. What I wanted was to increase the size of the center widget without any horizontal distance between them. I did it by setting enlargeCenterPage to true and enlargeStrategy to CenterPageEnlargeStrategy.height.