A list literal [1, 2, 3] builds an ordered collection. add appends, and reduce folds with a closure.

Program

Play the program to append a value and sum the list.

lists.dart
void main() {
  var nums = [1, 2, 3];
  nums.add(4);
  var total = nums.reduce((a, b) => a + b);
  print(total);
}
list literal `[1, 2, 3]` builds a `List<int>`.
add `add(x)` appends `x` in place.
reduce `reduce((a, b) => a + b)` folds the list to one value.