🎓 A1Learner
🔍
0 of 24 lessons completed

Dart Advanced Introduction

This course builds on the Dart Beginner and Intermediate courses. It covers streams in depth, records, patterns, extension types, isolates, and one taste of calling native code.

An awaited future

loadScore awaits the value 40 and returns 42. main awaits that future and prints the score.

Future<int> loadScore() async {
  var base = await Future.value(40);
  return base + 2;
}

Future<void> main() async {
  var score = await loadScore();
  print('score $score');
}

A list pipeline

The pipeline keeps the even numbers and doubles each one. The print shows the new list.

void main() {
  var nums = [1, 2, 3, 4];
  var doubled = [...nums.where((n) => n.isEven).map((n) => n * 2)];
  print(doubled);
}

A small class

Counter holds a count and bump raises it by one. Two bump calls leave the count at 2.

class Counter {
  int count = 0;

  void bump() {
    count += 1;
  }
}

void main() {
  var counter = Counter();
  counter.bump();
  counter.bump();
  print('count ${counter.count}');
}

Example

class Greeter {
  final String name;
  Greeter(this.name);

  String greet() {
    return 'Hello, $name';
  }
}

void main() {
  var greeter = Greeter('Ana');
  print(greeter.greet());
  print(greeter.name.length);
}

Key points

  • The opening lessons cover streams in depth, from listening to a stream to building and controlling one.
  • Records group a few values into one value, and patterns pull a value apart by its shape.
  • Extension types give an existing type a new name and its own members.
  • Isolates run code separately from the main program, so heavy work stays apart.
  • One lesson gives a first taste of calling native library code from Dart.
  • Dart also powers Flutter apps, and this course stays with plain Dart programs.

In this example, the Greeter class stores a name and builds a greeting from it. The first print shows the greeting, and the second print shows the length of the stored name.

Note

Every program in this course is a complete plain Dart program, and each one builds on the earlier courses.

Try it Yourself

Edit the code, then press Run.

Running is simulated · DartPad

Exercise

What does this course build on?