CodeBlanks Logo Icon CodeBlanks

Project design

Design the skeleton of the intermediate final mini app.

Project design

In this project we build a Task Manager console app. Each lesson adds one piece and builds on the previous solution.

Step by step: a Task class → a Trackable interface → collections → file input/output → combining with a Stream.

First the foundation: a Task class with an immutable title and a status field. Everything builds on it.

The Task class skeleton

The foundation class: class Task { final String title; bool done; Task(this.title, {this.done = false}); }.

title is immutable (final), done defaults to false. The constructor sets the field with the this.title shorthand.

This skeleton is the base for the interface, collections and file work in later lessons.

Practice Task class and an instance

Define a Task class with final String title and bool done fields, and a Task(this.title, {this.done = false}) constructor. In main create var t = Task('Code write'); and print print(t.title).

Starter code

main.dart
// Define the Task class

void main() {
  // create a Task instance and print the title
}

Sample solution

main.dart
class Task {
  final String title;
  bool done;
  Task(this.title, {this.done = false});
}

void main() {
  var t = Task('Code write');
  print(t.title);
}

Expected output

Code write

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 In which order does the project proceed?

  • Stream → file → class
  • File → class → Stream
  • Class → interface → collections → file → Stream Correct answer
  • Collections → class → interface

Explanation: first the class, then interface, collections, file and finally Stream.

2 Task constructor

Question
class Task { final String title; bool done; Task(____, {this.done = false}); }
Answer
class Task { final String title; bool done; Task(this.title, {this.done = false}); }

Explanation: the this.title shorthand sets the field.

3 Task class parts

Term Meaning
final String title Immutable title
bool done Status
this.title Constructor shorthand
{this.done = false} Default value

All lessons in Intermediate