Search code examples
flutterflutter-layoutflutter-dependenciesflutter-test

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


Solution

  • 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++;
    }