Real Libraries

Our main.dart is getting awfully crowded at this point. We have the main entry point, HipsterCollection, HipsterModel, HipsterView, and the various concrete classes. It’s too large to maintain easily and too entwined to let us reuse code.

To solve both problems, we move classes out into separate files. We will use Dart’s built-in library support to make this transition both smooth and well positioned for future reuse and maintainability.

Beginning with HipsterCollection, let’s create HipsterCollection.dart. To make this a proper Dart library, we need to start with the library directive. We also need to import the necessary core packages explicitly required by HipsterCollection.

mvc_library/public/scripts/HipsterCollection.dart ...

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.