Interview frequency: …
Short answer
Both make building a collection clearer: spread adds the elements of another collection, and collection-if adds them conditionally during construction.
Explanation
Use ... to copy a collection's elements into a new collection, and ...? when the source collection may be null. collection-if and collection-for add elements based on a condition or iteration without creating many temporary lists, which is useful when composing UI data.
Code example
final base = ["Dart"];
final topics = [
...base,
if (includeFlutter) "Flutter",
];Common mistakes
- Confusing adding the collection itself with adding its elements using spread.
- Using a nullable spread without ...? or a suitable check.