List.filled(length, value) creates a list of length copies of the same value, useful for a uniform initial state. List.generate(length, fn) builds a list by calling fn(i) for each index i in 0..length-1, so the elements can depend on position. Both constructors return a fresh List<T> with the requested length and avoid the manual for push pattern.

Program

Play the program to build a zero-filled buffer, a counted sequence, and a list of squares without writing a loop.

list_filled_generate.dart
void main() {
  var filled = List.filled(4, 0);
  var counted = List.generate(4, (i) => i + 1);
  var squares = List.generate(4, (i) => i * i);
  var summary = '$filled $counted $squares';
  print(summary);
}
List.filled `List.filled(n, v)` returns a list of `n` copies of `v`. Each slot is the same value; this is the right tool for a uniform initial state.
List.generate `List.generate(n, fn)` calls `fn(i)` for `i = 0..n-1` and collects the results. The index lets each element vary by position without writing a `for` loop.
constructor result Both factories return a fresh `List<T>` of the requested length, ready for downstream operations like `map`, `where`, or `join`.