Insert all elements of a collection into another collection.
The spread operator (...) unpacks all elements of an iterable and inserts them into a collection literal. It works with lists, sets, and maps, providing a concise way to combine and build collections.
The null-aware spread operator (...?) skips the spread if the expression evaluates to null, preventing a runtime error. This is useful when combining optional collections.
The spread operator is evaluated at runtime and can be combined with collection if and collection for to build complex collections declaratively. It creates a shallow copy of the spread elements; modifying the original collection after spreading does not affect the new collection.
var first = [1, 2, 3];
var second = [0, ...first, 4];
print(second); // [0, 1, 2, 3, 4]
List<int>? maybe = null;
var safe = [1, ...?maybe, 2];
print(safe); // [1, 2]