Search code examples
flutteruser-interfaceslidercarousel

how to customise the look of carousal slider in flutter?


I'm using flutter_carousel_widget package to make a carousel with this code:

 FlutterCarousel(
    options: CarouselOptions(
                physics: const NeverScrollableScrollPhysics(),
                controller: _carouselController,
                onPageChanged: (index, reason) {
                  currentView = index + 1;
           //setState is called to update the current page with respect to the current view
                  setState(() {});
                },
                height: 50.0,
                indicatorMargin: 10.0,
                showIndicator: true,
                slideIndicator: CircularWaveSlideIndicator(),
                viewportFraction: 0.9,
              ),
              items: swipeList.map((i) {
                return const Text('');
              }).toList(),
),

The above code outputs this kind of Carousel slider:

Result

But I would like to change the look of Corousel slider like below:

Expected


Solution

  • try the following code:

    import 'package:carousel_slider/carousel_options.dart';
    import 'package:carousel_slider/carousel_slider.dart';
    import 'package:flutter/material.dart';
    class Home extends StatelessWidget {
    
      @override
      Widget build(BuildContext context) {
    
        return Scaffold(
          body: Center(
            child: Container(
              width: double.infinity,
              height: 200,
              color: Colors.black,
              child:
              CarouselSlider(
                  options: CarouselOptions(
                    //  height: 100,
    
                    viewportFraction: .15,
                    enlargeCenterPage: true,
                    enableInfiniteScroll: false,
                    aspectRatio: 16/5,
                    disableCenter: true,
                    enlargeFactor: 0.35,
                    //autoPlay: true,
    
                  ),
                  items: List.generate(10, (index) => Container(
                    decoration: BoxDecoration(
                      color: Colors.white,
                      shape: BoxShape.circle,
                    ),
                  ))
              ),
            ),
          ),
        );
      }
    }
    

    the result:

    enter image description here

    Hope it helps you.