I want to print the index of array element as another array. I have array list name btns. It contains the value is true or false. I want the index of element having true. here my code is
List<bool> btn = [true, false, true, false, false, false, false];
Map<int, bool> map2 = btn.asMap();
var arr = new List<int>();
map2.forEach((key, value) {
if (value) {
print(key);
arr.add(key);
}
});
print(arr);
It is printin [0,2]. And showing correct results. But when I put in method. It showing error.
List<int> getbtnsInArray() {
Map<int, bool> map2 = btn.asMap();
var arr = new List<int>();
map2.forEach((key, value) {
if (value) {
print(key);
arr.add(key);
}
});
return arr;
}
print (getbtnsInArray);
It showing the error is Closure: () => List from Function 'getbtnsInArray':.
I don't know the reason. Please help me to find the answer.