Search code examples
fluttersliderflutter-dependenciescarousel

Carousal slider image is not taking width properly in flutter


I want like this

enter image description here

And I got this

enter image description here

            CarouselSlider(
              options: CarouselOptions(
              onPageChanged: (index, reason) {
                      setState(() {
                      _current = index;
                      });},

                autoPlayAnimationDuration:Duration(seconds: 1),
                autoPlayCurve: Curves.easeInOut,
                autoPlay: true,
                // height: 200,
                // initialPage: 0,
                // enlargeCenterPage: true,
              ),
              items: images.map((i) {
                return PageView(
                  controller: controller,
                  physics: BouncingScrollPhysics(),
                  children: [
                    Container(
                       // margin: EdgeInsets.symmetric(horizontal: 10.0),


                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(15),
                          // image: DecorationImage(
                          //     image:AssetImage(i),
                          //     fit: BoxFit.fill,
                          // ),
                        ),
                      child: Image.asset(i,fit: BoxFit.fitWidth, width: 350),
                    ),
                  ]
                );
              }).toList(),

            ),

Solution

  • you can fix it by using viewportFraction: 1.0, inside the CarouselOptions