Kumaresan Jackie
Kumaresan Jackie

Reputation: 111

How to find position in for loop in flutter?

for (var i in options) Text(i);

This is my for loop, I want to know the position of i How to find that position. I used that for loop in Flutter Widget.

I need the solution for use the for loop inside the widgets I want to know the position of i

Upvotes: 1

Views: 1641

Answers (2)

josxha
josxha

Reputation: 1227

You can use it like this:

for (int index = 0; i<options.length; i++) {
  var option = options[index];
  Text(option);
}

Edit: Maybe a outer index variable will do.

int index = 0;
for (var i in options) {
  Text(i);
  index++;
}

Upvotes: 1

Pathik Patel
Pathik Patel

Reputation: 1490

options.indexOf(i) will return the index of the element

Upvotes: 1

Related Questions