import 'package:flutter/material.dart'; import 'package:carousel_slider/carousel_slider.dart'; class Carousel extends StatefulWidget { Carousel({Key? key}) : super(key: key); @override State createState() => _CarouselState(); } final List imgList = [ 'assets/Carousel_1.webp', 'assets/Carousel_2.webp', 'assets/Carousel_3.webp' ]; class _CarouselState extends State { final List imageSliders = imgList .map((item) => Container( child: Container( margin: EdgeInsets.all(5.0), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(5.0)), child: Stack( children: [ Image.asset(item, fit: BoxFit.cover, width: 1000.0), Positioned( bottom: 0.0, left: 0.0, right: 0.0, child: Container( decoration: BoxDecoration( gradient: LinearGradient( colors: [ Color.fromARGB(200, 0, 0, 0), Color.fromARGB(0, 0, 0, 0) ], begin: Alignment.bottomCenter, end: Alignment.topCenter, ), ), padding: EdgeInsets.symmetric( vertical: 10.0, horizontal: 20.0), child: SizedBox( width: 1.0, ) ), ), ], )), ), )) .toList(); @override Widget build(BuildContext context) { return Container( child: CarouselSlider( options: CarouselOptions( aspectRatio: 2.0, enlargeCenterPage: true, enableInfiniteScroll: false, initialPage: 2, autoPlay: true, ), items: imageSliders, )); } }