total property
num
get
total
Returns the sum of all elements in the list.
If the list is null
or empty, it returns 0
.
Example:
List<num>? numbers = [1, 2, 3, 4, 5];
print(numbers.total); // 15
List<num>? emptyList = [];
print(emptyList.total); // 0
List<num>? nullList = null;
print(nullList.total); // 0
Implementation
num get total {
num t = 0;
if (isNotNullAndEmpty) {
for (var e in (this ?? [])) {
t += e;
}
}
return t;
}