CodeBlanks Logo Icon CodeBlanks

pub publish

Learn to publish packages with pub publish.

dart pub publish

dart pub publish sends your package to pub.dev. First you do a trial with dart pub publish --dry-run; this lists issues before publishing.

Before publishing pubspec must have a description, a license and a README. pub.dev checks these; it blocks publishing if anything is missing.

Published versions cannot be undone; so raise the version number carefully. From 1.0.0 to 1.0.1 is a patch, to 1.1.0 a minor, to 2.0.0 a major change.

Publishing checklist

Before publishing pubspec must be complete: name, description, version and environment. You also need a LICENSE file and a README.md.

CHANGELOG.md lists the changes in each version. pub.dev shows it to readers and presents the version history clearly.

The first publish asks for email verification. Later publishes need only your Google account.

Practice Package metadata

Import the library with import 'dart:convert';. In main print the result of jsonEncode({'package': 'hello', 'version': '1.0.0'}) with print.

Starter code

main.dart
// Import the dart:convert library

void main() {
  // print package metadata with jsonEncode
}

Sample solution

main.dart
import 'dart:convert';

void main() {
  print(jsonEncode({'package': 'hello', 'version': '1.0.0'}));
}

Expected output

{"package":"hello","version":"1.0.0"}

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Dry run publish

Question
dart pub publish --____
Answer
dart pub publish --dry-run

Explanation: --dry-run does a trial without publishing.

2 What does dart pub publish --dry-run do?

  • Checks without publishing Correct answer
  • Publishes the package
  • Deletes the package
  • Downgrades the version

Explanation: --dry-run checks without publishing.

3 Publishing parts

Term Meaning
dart pub publish Publishing
--dry-run Dry run
LICENSE License file
README.md Readme file

All lessons in Intermediate