简体   繁体   English

如何使用资产/图像在颤动中制作点指示器轮播滑块?

[英]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
             
            ),
        ),

I don't know how to declare the dotIndicator so that the dot autoplay with the images.我不知道如何声明 dotIndicator 以便点自动播放图像。

You can use a variable to track the current index from onPageChanged .您可以使用变量从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.

相关问题 如何在 flutter 中使用点指示器创建图像 slider? - How to create image slider with Dot Indicator in flutter? 如何在 carousel_slider 中使用资产图像? - How to work with asset images in carousel_slider? 我如何将 Dot Indicator 放在 flutter 中的 Carousel slider 上方,我尝试将堆栈设置为 position 它位于 carousel 图像上方,但它不起作用 - How can i put Dot Indicator above Carousel slider in flutter,i tried with stack to position it above the carousel image but its not working 是否可以将进度条作为指示器而不是带有图像滑块轮播的点指示器? - Is it possible to make progress bar as indicator instead of dot indicator with image slider carousel? 如何在颤动中使用轮播滑块制作不同的图片? - How to make different picture using carousel slider in flutter? Flutter 旋转木马 slider 指示灯颜色不变 - Flutter carousel slider indicator color not changing 如何在 flutter 中使用页码指示符而不是点指示符创建页面 slider? - How to create page slider with page number indicator instead of dot indicator in flutter? 如何在Flutter中制作具有渐变效果的轮播/滑块/图像切换器 - How to make carousel/slider/image switcher with fading effect in Flutter 如何使用滑块指示器更改颤动的字体大小? - How to change font size on flutter using a slider indicator? 无法在 Carousel Slider Flutter 中加载本地图像 - Cant load local images in Carousel Slider Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM