简体   繁体   中英

Reduce Flutter carousel slider padding

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:

输出

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM