Dart·Dart essentials

Small program

Combine collections and async into a small service.

Beginner 10 min read Lesson 5 of 150 Challenge included
What you will be able to do
  • Model with a class.
  • Fetch and map results.
  • Print a summary.

In plain English

Combine collections and async into a small service.

  • Model with a class.
  • Fetch and map results.
  • Print a summary.
service.dartDART
class Lesson {
  const Lesson(this.title, this.minutes);
  final String title;
  final int minutes;
}

void main() {
  const lessons = [Lesson('HTML', 12), Lesson('CSS', 18)];
  final total = lessons.fold<int>(0, (sum, l) => sum + l.minutes);
  print(total);
}
Your turn

Explain it back

Easy

Answer from memory: Which method folds a collection into one value?

TEXT · starter
Your answer…
Check your understanding before moving on.
Knowledge checkQuestion 1

Which method folds a collection into one value?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 5 of 150 · 0% of course