Hipster Models

Where the collection had a models property to store its data, the model will have the attributes property. Recall that the collection will pass the model a reference to itself, giving the model quick access to the collection’s properties (for example, url). Thus, we can begin defining the model class as follows:

 
class​ ComicBook {
 
Map attributes;
 
ComicsCollection collection;
 
 
ComicBook(​this​.attributes, {​this​.collection});
 
}

The declaration of the attributes and collection properties in this class should be familiar now. Each results in a setter/getter for ComicBook instances (for example, comic_book.collection = my_comics and comic_book.attributes[’title’]).

We previously saw Dart’s class constructor in ComicsCollection ...

Get Dart 1 for Everyone now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.