Collection Literals
Collection For
Inline Transformation
A for (var x in xs) inside a literal generates elements without a separate loop.
Program
Play the program to build a doubled copy of a list inline.
collection_for.dart
void main() {
var input = [1, 2, 3];
var doubled = [for (var n in input) n * 2];
print(doubled);
}
collection-for
`for (var n in input) n * 2` yields each transformed element.
comprehension-like
Compact alternative to `map` plus `toList`.
readable
The shape of the output list matches the literal.