Parts

The part directive is used to include arbitrary chunks of Dart code into the current context. Consider, for instance, a library that has clearly grown too big for its britches, the simple_multiples library.

libraries/simple_multiples.dart
 
library​ simple_multiples;
 
quadruple_triple_double(x) => 4 * triple_double(x);
 
triple_double(x) => 3 * double(x);
 
double(x) => 2 * x;

Okay. No one in their right mind would want to split such a simple library into parts, but hipsters aren’t necessarily in their right mind. So let’s pull this library apart just to see how we might do it.

To really explore parts, we leave the double method in the current library and move the other two methods out into their own files. Our simple_multiples.dart would ...

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.