total property

double get total

Calculates the total sum of the doubles in the iterable.

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

Example:

Iterable<double?>? numbers = [1.5, 2.5, null, 4.0];
double sum = numbers.total; // sum is 8.0

Implementation

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