Flutter ● ○ ○ Dart 3.6

Kodebits Day 9: Collection If

Apr 20 2026
Build a Dart list dynamically with collection-if.

What does this print?

void main() {
  var vip = true;
  final tags = [
    'new',
    if (vip) 'vip',
  ];
  print(tags);
}


Try it in the online Dart Playground →

[spoiler title="Solution"]

Answer:

[new, vip]

Explanation:

collection-if inserts ‘vip’ only when vip is true.

[/spoiler]


Further Reading