Book Image

Learning Dart

Book Image

Learning Dart

Overview of this book

Table of Contents (19 chapters)
Learning Dart
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Spiral 2 – drawing cells


In this spiral, we will give our app code some structure: Board is a view, so board.dart is moved to the view folder. We also introduce here the Memory class from our model in its own code file memory.dart in the model folder. So, we have to change the part statements to the following:

part 'model/memory.dart';
part 'view/board.dart';

The Board view needs to know about Memory. So, we will include it in the Board class and make its object in the Board constructor:

new Board(canvas, new Memory(4));

The Memory class is still very rudimentary with only its length property:

class Memory {
  num length;
  Memory(this.length);
}

Our Board class now also needs a method to draw the lines, which we decided to make private because it is specific to Board, as well as the methods clear() and border():

void draw() {
    _clear();
    _border();
    _lines();
}

The lines method is quite straightforward; first draw it on a piece of paper and then translate it to code using moveTo and lineTo...