total property

num get total

Calculates the total sum of the numbers in the iterable.

  • Returns 0 if the iterable is null or empty.
  • Null elements within the iterable are treated as 0.

Example:

Iterable<num?>? numbers = [1, 2, null, 4];
num sum = numbers.total; // sum is 7

Implementation

num get total {
  if (isEmptyOrNull) return 0;
  num sum = 0;
  for (final current in this!) {
    sum += current ?? 0;
  }
  return sum;
}