我在flutter的故事视图中使用图像列表,我想获得屏幕上显示的列表的索引。这是我的代码
StoryView(
storyItems: images
.map((e) => StoryItem.pageImage(
url: e,
// caption: "",
controller: newController,
))
.toList(),
onStoryShow: (s) {},
onComplete: () {
print("Completed a cycle");
Navigator.pop(context);
},
onVerticalSwipeComplete: (direction) {
if (direction == Direction.down) {
Navigator.pop(context);
}
},
progressPosition: ProgressPosition.top,
repeat: false,
controller: storyController,
),
我能想到的只有这个
-
将密钥添加到StoryItem视图图像
-
然后在onStoryShow中添加查看图像
-
最后将var"0"发送到服务器;storyId";
您可以对列表执行.asMap()
,将列表项更改为具有索引的条目。
const arr = ['a', 'b', 'c'];
arr.asMap().entries.map((entry) {
int index = entry.key;
String val = entry.value;
return entry;
});