Untitled
unknown
plain_text
3 years ago
2.9 kB
12
Indexable
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
class HomeSliderComponent extends StatefulWidget {
const HomeSliderComponent({super.key});
@override
State<HomeSliderComponent> createState() => _HomeSliderComponentState();
}
class _HomeSliderComponentState extends State<HomeSliderComponent> {
int _currentIndex = 0;
final addddd = [
'images/img/Thumbnail.png',
'images/img/slide2.png',
'images/img/Thumbnail.png',
];
final CarouselController _controller = CarouselController();
@override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width - 30.0;
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(children: [
CarouselSlider(
carouselController: _controller,
items: addddd
.map(
(item) => SizedBox(
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Center(
child: Image.asset(
item,
fit: BoxFit.cover,
width: double.infinity,
),
),
),
),
)
.toList(),
options: CarouselOptions(
//height: 110.0,
aspectRatio: 16 / 9,
// pageSnapping: false,
// height: 180,
autoPlay: true,
autoPlayInterval: Duration(seconds: 5),
viewportFraction: 1.0,
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
enlargeCenterPage: false,
scrollDirection: Axis.horizontal,
onPageChanged: (index, reason) {
setState(() {
_currentIndex = index;
});
}),
),
Positioned(
bottom: 25,
//left: 150,
left: (screenWidth - (2 * (addddd.length) - 1) * 8.0) / 2.0,
child: AnimatedSmoothIndicator(
activeIndex: _currentIndex,
count: addddd.length,
duration: Duration(milliseconds: 500),
effect: WormEffect(
spacing: 8.0,
dotHeight: 8.0,
dotWidth: 8.0,
dotColor: Colors.white,
activeDotColor: Colors.black87,
),
),
),
]),
],
);
}
}
Editor is loading...