flutterdartcarouselcarousel-slider

Flutter Carousel Slider Assertion Error firstIndex == 0


I am using flutter carousel_slider 4.2.1 it works perfect but in 5 seconds there is a error message showing.

CarouselController carouselController = CarouselController();
  
    return Container(
      height: MediaQuery.of(context).size.height,
      padding: EdgeInsets.only(top: 18, right: 20, left: 20),
      decoration: BoxDecoration(
          color: white,
          borderRadius: BorderRadius.vertical(top: Radius.circular(18))),
      child: ListView(
        children: [
          Container(
            width: MediaQuery.of(context).size.width - 40,
            decoration: BoxDecoration(
                color: grey, borderRadius: BorderRadius.circular(24)),
            height: 200,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(24),
              child: CarouselSlider(
                carouselController: carouselController,
                items: _imageList,
                options: CarouselOptions(
                    autoPlay: true, autoPlayCurve: Curves.linear),
              ),
            ),
          ),
         
        ],
      ),
    );

and this error shows in 5 seconds

_AssertionError ('package:flutter/src/rendering/sliver_fixed_extent_list.dart': Failed assertion: line 270 pos 12: 'firstIndex == 0 || childScrollOffset(firstChild!)! - scrollOffset <= precisionErrorTolerance': is not true.)

Solution

  • I don't know what you put inside _imageList but to return widget from the _imageList you should write like this _imageList.map((e) => put some widget here that you want for the carousel).toList()