Thuta Learning
BasicProgrammingbeginner

Collections (Lists)

Relax. We'll talk through this in plain words — no textbook voice.

List is an ordered collection that stores items by index. Dart's List is similar in some ways to a JavaScript Array, but with better type safety.

dart
void main() {
  List<String> lessons = ['Syntax', 'Variables', 'Functions'];

  print('First lesson: ${lessons[0]}');

  lessons.add('Null Safety');

  for (final lesson in lessons) {
    print('Learn: $lesson');
  }
}

List means this List will only hold Strings. Since indexes start at 0, you grab the first item with lessons[0].

You should see
First lesson: Syntax Learn: Syntax Learn: Variables Learn: Functions Learn: Null Safety

Easy traps

  • If a List has 3 items, the valid indexes are 0, 1, and 2. Calling lessons[3] can cause a range error.
Collections (Lists) | Thuta Learning