Often Dart libraries are small enough to be entirely contained in a single file.
However, when the file becomes too large and it’s not possible to split the library into smaller libraries (as advised by the Dart team in the note
here), Dart defines a part of
directive, which
allows developers to split the library into multiple smaller chunks.
When a library is split into multiple files, each part has to refer the library it belongs to, and it can do so with two similar but alternative
syntaxes:
- by name identifier:
part of my_library;
- by a URI string:
part of 'my_library.dart';
The second syntax is more precise and flexible, because it explicitly identifies the file that contains the main body of the library, whereas a
reference by identifier needs to be resolved to a URI by the Dart compiler.
What is the potential impact?
If the part of
directive is used with a library name, the Dart compiler may resolve the library incorrectly, if multiple libraries
with the same name but different paths exist in the package.