🍇 List
Use the array-like Dart List to manage a collection of objects
Basic Lists
lists.dart
List<int> list = [1, 2, 3, 4, 5];
list[0]; // 1
list.length; // 5
list.last; // 5
list.first; // 1
Loops
lists.dart
for (int n in list) {
print(n);
}
list.forEach((n) => print(n));
var doubled = list.map((n) => n * 2);
Spread Syntax
lists.dart
var combined = [...list, ...doubled];
combined.forEach(print);
Conditions in Lists
lists.dart
bool depressed = false;
var cart = [
'milk',
'eggs',
if (depressed) 'Vodka'
];