Home > Software engineering >  Flutter - calculate the number of true bool values there are in a dynamic list of just bools
Flutter - calculate the number of true bool values there are in a dynamic list of just bools

Time:04-16

in my app, there is a section where the user is answering a series of questions created by themselves, to which the only responses to it is either true or false. The method I tried was adding the response to an array at that question's index, then after finishing the questions , there would be a method to add up the number of true values in the array, and give the result as a score

CodePudding user response:

this sample might help you:

 List<bool> list = [true, false, true];

 print(list.where((x) => x == true).length);

where the output would be 2

  • Related