Home > Blockchain >  Remove margin between carousel images
Remove margin between carousel images

Time:08-25

Why is there a vertical margin line between images in this Flutter carousel? The line is flickering when I slide the carousel.

This bug happens on the device (Nokia 7 Plus) but not the emulator.

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';

main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: ListView(
          children: [
            Text('Test'),
            CarouselSlider(
              options: CarouselOptions(
                aspectRatio: 1.8,
              ),
              items: List.generate(5, ((i) {
                return Container(
                  color: Colors.grey[200],
                  child: Column(
                    children: [
                      Image.network(
                        'http://picsum.photos/id/$i/400/200',
                      ),
                      Text('TEST'),
                    ],
                  ),
                );
              })),
            ),
          ],
        ),
      ),
    ),
  );
}

What I have:

enter image description here

What I want:

enter image description here

CodePudding user response:

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

I recommend to have a look at the examples enter image description here

  • Related