Anyone know how to set all data of List<bool> to be false?
Here is example:
List<bool> data = [true, false, true];
data = [false, false, false];
// output data = [false, false, false]
and there is my code to convert it, and i know that we can do with looping.
But here, i want to do with some function, which is i was tried with data.every((element) => element = false); but, that is not working.
Thanks in advance
CodePudding user response:
void main() {
List<bool> data = [true, false, true];
print('first origin data: $data');
data = List<bool>.filled( data.length, false);
print('first origin data: $data\n');
data = [true, false, true];
print('second origin data: $data');
for (var loop = 0 ; loop < data.length ; loop ) {
data[loop] = false;
}
print('second modified data: $data\n');
data = [true, false, true];
print('third origin data: $data');
data.asMap().forEach((index, value) {
if (value == true) {
data[index] = false;
}
});
print('third modified data: $data\n');
}

