Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exact meaning of "library" keyword in dart

Tags:

dart

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

Could somebody explain what the "library" keyword in Dart does?

like image 685
romanos Avatar asked Jan 26 '14 15:01

romanos


People also ask

What is library in flutter?

It is a complete software development kit (SDK). A library is essentially a collection of subprograms used in the software development process. Libraries contain data and ancillary codes that offer standalone program services. They allow modular sharing and modification of data and code.

What are the keywords are used to make a custom library in Dart?

The Dart provides the import keyword, which is used to make the library available in the current file. We can use multiple libraries in a single file. For example - Dart built-in library URIs is used as dart scheme to refer to a library.

How do I import library to Dart?

When importing a library file from another package, use the the package: directive to specify the URI of that file. import 'package:utilities/utilities. dart'; When importing a library file from your own package, use a relative path when both files are inside of lib, or when both files are outside of lib.


1 Answers

update 2018-03-05

For a while now, part of accepts a URI, which reduces the need of library to a few edge cases.

update 2015-11-27

With a recent change, two imported nameless libraries don't produce a warning anymore. The plan is to make the library declaration entirely optional.


The library declaration is optional. If it is omitted the library name defaults to "".
There are some situations (pub build) where you get an error if two libraries have the same name, so it's usually good practice to set proper library names.

In a simple command line app consisting of one library it's usually fine to omit the library declaration.

From the Dart language spec

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

The name of a library is used to tie it to separately compiled parts of the library (called parts) and can be used for printing and, more generally, reflection. The name may be relevant for further language evolution.

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

like image 122
Günter Zöchbauer Avatar answered Sep 18 '22 09:09

Günter Zöchbauer