An if (cond) value inside a literal includes the value only when the condition is true.

Program

Play the program to include a bonus element when a flag is on.

collection_if.dart
void main() {
  var includeBonus = true;
  var items = ['a', 'b', if (includeBonus) 'bonus'];
  print(items);
}
collection-if `if (cond) value` lives inside a list/set/map literal.
inline branching Avoids building the list and patching it later.
clarity Reads like the data layout itself.