Open jamesderlin opened 5 years ago
I'll also add that a lot of Dart documentation (e.g. the "Libraries and visibility" section of the Language Tour talks about "libraries" and mentions that identifiers with a leading _
are private to the library, but it doesn't explain what a library is (other than "Every Dart app is a library", but that raises more questions). Is a library normally a single .dart
file? The directory?
Every Dart app is a library
is perhaps the most confusing and misleading sentence in all of our docs.
I cannot find documentation anywhere about what the library name is used for. The library is imported using its file name (not the library name). It looks like it is used for resolving deferred imports. What else? This should be documented!
This is indeed difficult to figure out. Based on the information a google search can provide it seems that the library directive is intended to make the following private access work, but it doesn't.
File base_thing.dart
:
library thing;
import 'my_imports';
class BaseThing {
void _doAThing() {}
}
File thing.dart
:
library thing;
import 'my_other_imports';
import 'base_thing.dart';
class Thing extends BaseThing {
void doMyThing() {
_doAThing();
}
}
The solution seems to be to use part
, part of
directives, but that doesn't really work if I have a Thing2
that also wants access to BaseThing
.
Page URL: https://www.dartlang.org/guides/libraries/create-library-packages Page source: https://github.com/dart-lang/site-www/tree/master/src/_guides/libraries/create-library-packages.md
Description: https://dart.dev/language/libraries has:
However, the linked "Create Library Packages" page doesn't explain the
library
orpart
directives at all. It only has notes such as:None of these explain what
library
andpart
do nor provide any examples for how to use them.While their usage might be discouraged, they're still part of the language, and it would be nice to document somewhere what they are and what they do.