
Creating Dart libraries
A Dart library can be composed of a single file or multiple files. In the most common and recommended way, when you create a file, you create a small library. But, if you prefer, you can split a library definition into multiple files. Although less common, it can be useful depending on the context, especially when working with very interdependent classes, for example.
The decision for splitting is important, not only for encapsulation but also for how library customers will import and use them. Let's say, for example, that we have two tightly coupled classes that need to live together for them to work. Dividing them into different libraries will force customers to import both libraries. This is not the most practical way, so it's very important to be careful of library splitting when creating open source libraries.
Before we get into alternative ways of defining a library, we need to take a look at library privacy; this helps with encapsulation, making it easier to understand why we need to properly split a library into multiple files or not.