A library is the privacy boundary in Dart. A package can expose a small public library while keeping implementation files under lib/src/. Consumers should import the public contract instead of depending on internal file layout.
Organize a small reusable package
invoice_tools/
lib/invoice_tools.dart
lib/src/invoice.dart
test/invoice_test.dart
pubspec.yaml
The public entry point can export only selected declarations:
export 'src/invoice.dart' show Invoice, InvoiceFormatException;
An import can use a prefix to avoid naming ambiguity, or one show/hide combinator to keep a clear scope. Do not treat every implementation file as part of the supported API. Underscore declarations are library-private; part files share the library rather than creating independent privacy boundaries.
Document the behavior consumers rely on
Use doc comments to explain valid inputs, output meaning and expected failures. Add a tiny example and tests for important contracts. A method’s name and type often communicate more than a long comment describing an obvious assignment.
Annotations are metadata used by tools or libraries; they do not automatically generate code. If you choose generated serialization, declare the generator and run its supported build command. Review generated output assumptions and keep the source model as the editable authority.
Prepare a release without publishing it accidentally
Run formatting, analysis and tests. A dart pub publish --dry-run can inspect package readiness without uploading. Before a real publish, review which files would ship, the license, public API and semantic-version implications. Keep credentials, local configuration and caches outside the package archive.
For precise publishing behavior, use the package publication guide . This course does not publish a package for you.
Exercise
Create an invoice package exposing only its model and parser. Import it from a console consumer and verify that internal helper names are not part of the documented entry point. Describe which change would require a major version because it breaks existing callers.