Dart/Flutter 有没有办法找到我的轮播的索引?

Dart/Flutter Is there a way to find the index of my carousel?

有没有办法找到轮播项目的索引,以便我可以使用它来检索相关文本和 link 与显示的项目相关联??

所以我有 3 个列表,一个图像列表,一个文本列表和一个 url 列表。

有没有办法找到关联的 index/key 来重用??

         child: Container(
                      child: CarouselSlider(
                        options: CarouselOptions(
                          enlargeCenterPage: true,
                          enableInfiniteScroll: true,
                          autoPlay: true,
                          // pageSnapping: true,
                        ),
                        items: listThumbs.map((e) => ClipRRect(
                          borderRadius: BorderRadius.circular(8),
                          child: Stack(
                            //fit: StackFit.expand,
                            children: <Widget>[
                            Image.network(e,
                            width: 1050,
                            height: 350,
                            fit: BoxFit.cover,
                            ),
                          Text(videObj.results[INDEX].name),
                         ] ),
                        )).toList(),
                      )),

您可以尝试使用构建器方法。

旋转木马滑块example


CarouselSlider.builder(
  itemCount: 15,
  itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) =>
    Container(
      child: Text(itemIndex.toString()),
    ),
)

此方法将给出每个项目的index

可以在地图迭代区调用'indexOf'

int idx = listThumbs.indexOf(e);
         child: Container(
                      child: CarouselSlider(
                        options: CarouselOptions(
                          enlargeCenterPage: true,
                          enableInfiniteScroll: true,
                          autoPlay: true,
                          // pageSnapping: true,
                        ),
                        items: listThumbs.map((e) {
                          // Here you can find item index.
                          int idx = listThumbs.indexOf(e);

                          return ClipRRect(
                            borderRadius: BorderRadius.circular(8),
                            child: Stack(
                              //fit: StackFit.expand,
                              children: <Widget>[
                                Image.network(e,
                                  width: 1050,
                                  height: 350,
                                  fit: BoxFit.cover,
                                ),
                                Text(videObj.results[INDEX].name),
                              ]),
                             );
                            }
                          )).toList(),
                      )),