繁体   English   中英

如何在 flutter 中使用点指示器创建图像 slider?

[英]How to create image slider with Dot Indicator in flutter?

带有点指示器的示例图像

我有多个图像,每个图像都有自己的重定向链接。 目前,这在使用列表视图构建显示手势检测器内的图像时效果很好。

但是,我想添加一个点指示器来显示正在查看的图像。 如何获取正在显示的图像的索引? 或在向左或向右滑动时增加/减少计数器。

您应该发布您所做的代码,以便人们可以看到您的确切问题是什么。

如果您使用 ListView.builder,则可以从 itemBuilder 获取索引。 然后在与列表交互时创建一个变量来保存该索引的值

int currentIndex;

itemCount: list.length,
itemBuilder: (context, index) {
  currentIndex = index;
}

然后在 listView 下方,添加一个自定义点指示器列表。

Row(
  children: [
    for(int i = 0; i < list.length; i++)
      Container(
        height: 10, width: 10,
        decoration: BoxDecoration(
          color: i == currentIndex ? Colors.white : Colors.grey,
          borderRadius: BorderRadius.circular(5)
        )
      )
  ]
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM