9

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

2 Answers 2

21

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
-1

You also Try to change Change This Value Like this

                 autoPlayCurve: Curves.fastOutSlowIn,
                 aspectRatio: 18/9,
                 viewportFraction: 0.9,
                 enlargeCenterPage: true,
                 enableInfiniteScroll: true,
                 enlargeStrategy: CenterPageEnlargeStrategy.zoom,
                 padEnds: true,

```[enter image description here][1]

[enter image description here][2]


  [1]: https://i.sstatic.net/86xdE.jpg

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.