Dart library vs lib Dart library vs lib dart dart

Dart library vs lib


Ultimately, there is no relation between your directory structure and the library keyword in Dart.

The dart directory structure comes from the recommended package layout conventions but are not enforced by the language in any way. They are only enforced if you try to use the pub package manager to publish (upload) your package to the official dart repository. Ultimately you can use whatever directory structure layout you choose. This one is recommended to keep consistency between packages, particularly for Open Source packages or applications which may have other external contributors.

The library keyword in Dart is used in a way of namespacing. For instance the underscore private variables are only have library visibility. Anything in the same library can see/access your underscore variables. Anything outside of it cannot. You can use the part and part of keywords to make other files part of a library (regardless of where they are located in the directory structure).


The lib directory has no relationship with the library declaration.You can declare a library consisting of one or more dart files no matter in which directory the files are stored.Several files consisting one library don't need even to be stored in the same directory.

If you want to make a package available as a library the convention is to store the files consisting the public API in the lib directory and library private API in lib/src. Even here there could be several libraries in lib and several libraries in lib/src.