🍇 List

Use the array-like Dart List to manage a collection of objects

Basic Lists

file_type_dartlang lists.dart
List<int> list = [1, 2, 3, 4, 5];

list[0]; // 1

list.length; // 5
list.last; // 5
list.first; // 1

Loops

file_type_dartlang lists.dart
  for (int n in list) {
    print(n);
  }

list.forEach((n) => print(n));

var doubled = list.map((n) => n * 2);

Spread Syntax

file_type_dartlang lists.dart
var combined = [...list, ...doubled];
combined.forEach(print);

Conditions in Lists

file_type_dartlang lists.dart
bool depressed = false;
var cart = [
    'milk', 
    'eggs', 
    if (depressed) 'Vodka'
];

Questions? Let's chat

Open Discord