I have list List<bool> _selections = [false, true, false]; and this list may change only one can be true

How do I know which index is true ?


Solution 1: Uj Corb

you can use indexWhere

_selections.indexWhere((value) => value)


Solution 2: mducc

You can try indexWhere() method.

_selections.indexWhere((ele) => ele);

See more


Solution 3: hewa jalal

while the above answer are correct and simpler you can also use a good old foreach loop like this:

for (var elements in _selections) {
    if (elements == true) {
      print(elements);
    }
  }