Home > front end >  I want to calculate each number from the array in flutter
I want to calculate each number from the array in flutter

Time:04-23

I have an array in the flutter

 final list = [1, 2, 3, 4, 5];

I want to calculate each number from the array how i can?

CodePudding user response:

Try the following:

 final list = [1, 2, 3, 4, 5];

 final result = list.reduce((sum, element){
 return sum   element;
 }); 

CodePudding user response:

This could do it

final sum = list.fold<int>(0, (previousValue, number) => previousValue   number);
  • Related