Reputation: 3451
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 ?
Upvotes: 1
Views: 1411
Reputation: 963
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);
}
}
Upvotes: 2
Reputation: 743
You can try indexWhere()
method.
_selections.indexWhere((ele) => ele);
Upvotes: 2