Collection if and for
Build lists conditionally and in loops.
Logic Inside Literals
Sometimes a list's contents depend on a condition. Dart lets you put an if right inside the collection literal, so you build it in one place.
Collection if
A collection if adds an element only when its condition is true. No condition met means that slot simply contributes nothing.
var nav = ['Home', if (loggedIn) 'Profile'];All lessons in this course
- The Cascade Operator (..)
- Null-Shorting Cascades (?..)
- Spread and Null-Aware Spread
- Collection if and for