How to get current index of Story view in flutter

Viewed 24

Im using list of images in story view in flutter, i want to get index of the list which is being displayed on the screen. This is my code

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,
          ),
1 Answers

You can do .asMap() to the list to change the list item to entry, which has the index.

const arr = ['a', 'b', 'c'];
arr.asMap().entries.map((entry) {
    int index = entry.key;
    String val = entry.value;
    return entry;
});
Related