The exact meaning of the keyword dart

I know that this keyword should be used in some user library, but when I dropped it, nothing happened (at least I didn't notice anything), the import still worked fine, private members remained private.

Can someone explain what the "library" keyword is in Dart?

+7
dart
source share
1 answer

update 2018-03-05

part of , since it takes a URI for some time, which reduces the need for a library in several edg3 cases.

update 2015-11-27

With a recent change, two imported nameless libraries no longer give a warning. The plan is to make the declaration of the library completely optional.


A library declaration is optional. If omitted, the default library name is "" .
There are several situations ( pub build ) where you get an error if two libraries have the same name, so it is usually recommended to set the correct library names.

On a simple command line, an application consisting of a single library is usually excellent to omit the library declaration.

From Dart Language Specification

An implicitly named library has an empty string as its name.

The name of the library is used to bind to separately compiled parts of the library (called parts) and can be used for printing and, more generally, reflective. The name may be related to further language evolution.

Libraries intended for widespread use should avoid name conflicts. The Dart pub package management system provides a mechanism for doing so. Each pub package is guaranteed a unique name, effectively enforcing the use of the global namespace.

+7
source share

All Articles