[英]How to make dot indicator carousel slider in flutter using asset/images?
CarouselSlider(
options: CarouselOptions(
),
items: [
Image.asset('images/pizza.png'),
],
),
DotsIndicator(
dotsCount: 4,
position: dotPosition.toDouble(),
//declare the position to autoplay
),
),
我不知道如何聲明 dotIndicator 以便點自動播放圖像。
您可以使用變量從onPageChanged
跟蹤當前索引。
class _MyWidgetState extends State<MyWidget> {
final items = [
Image.asset('images/drumstick.png'),
Image.asset('images/pizza.png')
];
int currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
CarouselSlider(
options: CarouselOptions(
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
onPageChanged: (index, reason) {
setState(() {
currentIndex = index;
});
},
),
items: items,
),
DotsIndicator(
dotsCount: items.length,
position: currentIndex.toDouble(),
)
],
),
),
);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.