void main() {
var numbers = [5, 10, -4, 27, -8, 6, -2];
var sum1 = 0;
sum1 = numbers.fold(0, (previous, current) => previous + current);
print("Sum 1: ${sum1}");
var sum2 = 0;
sum2 = numbers.where((number) => number > 0).fold(0, (previous, current) => previous + current);
print("Sum 2: ${sum2}");
}
Output
Sum 1: 34
Sum 2: 48