CINXE.COM
Creating packages | Dart
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><script>!function(e,t,a,n){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var g=t.getElementsByTagName(a)[0],m=t.createElement(a);m.async=!0,m.src="https://www.googletagmanager.com/gtm.js?id=GTM-5VSZM5J",g.parentNode.insertBefore(m,g)}(window,document,"script","dataLayer")</script><meta name="description" content="Learn how to create packages in Dart."><title>Creating packages | Dart</title><link rel="icon" sizes="64x64" href="/assets/img/logo/dart-64.png" eleventy:ignore><link href="/assets/img/touch-icon-iphone.png" rel="apple-touch-icon" eleventy:ignore><link href="/assets/img/touch-icon-ipad.png" rel="apple-touch-icon" sizes="152x152" eleventy:ignore><link href="/assets/img/touch-icon-iphone-retina.png" rel="apple-touch-icon" sizes="180x180" eleventy:ignore><link href="/assets/img/touch-icon-ipad-retina.png" rel="apple-touch-icon" sizes="167x167" eleventy:ignore><meta name="twitter:card" content="summary"><meta name="twitter:site" content="@dart_lang"><meta name="twitter:title" content="Creating packages"><meta name="twitter:description" content="Learn how to create packages in Dart."><meta property="og:title" content="Creating packages"><meta property="og:description" content="Learn how to create packages in Dart."><meta property="og:url" content="/guides/libraries/create-packages/"><meta property="og:image" content="/assets/img/logo/dart-logo-for-shares.png?2" eleventy:ignore><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Display:wght@400&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Mono:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Google+Sans+Text:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet"><link rel="stylesheet" href="/assets/css/main.css"><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/4.6.2/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.5/js.cookie.min.js" integrity="sha512-nlp9/l96/EpjYBx7EP7pGASVXNe80hGhYAUrjeXnu/fyF5Py0/RXav4BBNs7n5Hx1WFhOEOWSAVjGeC3oKxDVQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><script src="/assets/js/os-tabs.js"></script><script src="/assets/js/utilities.js"></script><script src="/assets/js/main.js"></script><script>!function(e,a,t,n,c,o,s){e.GoogleAnalyticsObject=c,e[c]=e[c]||function(){(e[c].q=e[c].q||[]).push(arguments)},e[c].l=1*new Date,o=a.createElement(t),s=a.getElementsByTagName(t)[0],o.async=1,o.src="//www.google-analytics.com/analytics.js",s.parentNode.insertBefore(o,s)}(window,document,"script",0,"ga"),ga("create","UA-26406144-4","auto"),ga("send","pageview")</script></head><body class="default.html show_banner"><a id="skip" href="#site-content-title">Skip to main content</a><section id="cookie-notice"><div class="container"><p>dart.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic. <a href="https://policies.google.com/technologies/cookies" target="_blank" rel="noopener">Learn more</a>.</p><button id="cookie-consent" class="btn btn-primary">OK, got it</button></div></section><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5VSZM5J" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript><header id="page-header" class="site-header"><nav id="mainnav" class="site-header"><div id="menu-toggle"><i class="material-symbols">menu</i></div><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart"></a><ul class="navbar"><li><a href="/overview" class="nav-link">Overview</a></li><li class="mainnav__get-started"><a href="/guides" class="nav-link active"><span>Docs</span></a></li><li><a href="/community" class="nav-link">Community</a></li><li><a href="/#try-dart" class="nav-link">Try Dart</a></li><li><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="searchfield"><form action="/search" class="site-header__search form-inline" id="cse-search-box"><input type="hidden" name="cx" value="011220921317074318178:_yy-tmb5t_i"> <input type="hidden" name="ie" value="UTF-8"> <input type="hidden" name="hl" value="en"> <input class="site-header__searchfield form-control search-field" type="search" name="q" id="search-main" autocomplete="off" placeholder="Search" aria-label="Search"></form></li></ul></nav></header><div class="banner"><p class="banner__text">Announcing Dart 3.5 and an updated Dart roadmap! <a href="https://medium.com/dartlang/dart-3-5-6ca36259fa2f" target="_blank">Learn more</a></p></div><div id="sidenav"><form action="/search/" class="site-header__search form-inline"><input class="site-header__searchfield form-control search-field" type="search" name="q" id="search-side" autocomplete="off" placeholder="Search" aria-label="Search"></form><div class="site-sidebar"><ul class="navbar-nav"><li class="nav-item"><a href="/overview" class="nav-link">Overview</a></li><li class="nav-item"><a href="/community" class="nav-link">Community</a></li><li class="nav-item"><a href="https://dartpad.dev" class="nav-link">Try Dart</a></li><li class="nav-item"><a href="/get-dart" class="nav-link">Get Dart</a></li><li class="nav-item"><a href="/guides" class="nav-link">Docs</a></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li></ul><ul class="nav flex-column"><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-1" role="button" aria-expanded="false" aria-controls="sidenav-1">Language</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1"><li class="nav-item"><a class="nav-link" href="/language">Introduction</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-2" href="#sidenav-1-2" role="button" aria-expanded="false" aria-controls="sidenav-1-2">Syntax basics</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-2"><li class="nav-item"><a class="nav-link" href="/language/variables">Variables</a></li><li class="nav-item"><a class="nav-link" href="/language/operators">Operators</a></li><li class="nav-item"><a class="nav-link" href="/language/comments">Comments</a></li><li class="nav-item"><a class="nav-link" href="/language/metadata">Metadata</a></li><li class="nav-item"><a class="nav-link" href="/language/libraries">Libraries & imports</a></li><li class="nav-item"><a class="nav-link" href="/language/keywords">Keywords</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-3" href="#sidenav-1-3" role="button" aria-expanded="false" aria-controls="sidenav-1-3">Types</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-3"><li class="nav-item"><a class="nav-link" href="/language/built-in-types">Built-in types</a></li><li class="nav-item"><a class="nav-link" href="/language/records">Records</a></li><li class="nav-item"><a class="nav-link" href="/language/collections">Collections</a></li><li class="nav-item"><a class="nav-link" href="/language/generics">Generics</a></li><li class="nav-item"><a class="nav-link" href="/language/typedefs">Typedefs</a></li><li class="nav-item"><a class="nav-link" href="/language/type-system">Type system</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-4" href="#sidenav-1-4" role="button" aria-expanded="false" aria-controls="sidenav-1-4">Patterns</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-4"><li class="nav-item"><a class="nav-link" href="/language/patterns">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/pattern-types">Pattern types</a></li><li class="nav-item"><a class="nav-link" href="https://codelabs.developers.google.com/codelabs/dart-patterns-records" target="_blank" rel="noopener">Applied tutorial</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/language/functions">Functions</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-6" href="#sidenav-1-6" role="button" aria-expanded="false" aria-controls="sidenav-1-6">Control flow</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-6"><li class="nav-item"><a class="nav-link" href="/language/loops">Loops</a></li><li class="nav-item"><a class="nav-link" href="/language/branches">Branches</a></li><li class="nav-item"><a class="nav-link" href="/language/error-handling">Error handling</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-7" href="#sidenav-1-7" role="button" aria-expanded="false" aria-controls="sidenav-1-7">Classes & objects</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-7"><li class="nav-item"><a class="nav-link" href="/language/classes">Classes</a></li><li class="nav-item"><a class="nav-link" href="/language/constructors">Constructors</a></li><li class="nav-item"><a class="nav-link" href="/language/methods">Methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extend">Extend a class</a></li><li class="nav-item"><a class="nav-link" href="/language/mixins">Mixins</a></li><li class="nav-item"><a class="nav-link" href="/language/enums">Enums</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-methods">Extension methods</a></li><li class="nav-item"><a class="nav-link" href="/language/extension-types">Extension types</a></li><li class="nav-item"><a class="nav-link" href="/language/callable-objects">Callable objects</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-8" href="#sidenav-1-8" role="button" aria-expanded="false" aria-controls="sidenav-1-8">Class modifiers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-8"><li class="nav-item"><a class="nav-link" href="/language/class-modifiers">Overview & usage</a></li><li class="nav-item"><a class="nav-link" href="/language/class-modifiers-for-apis">Class modifiers for API maintainers</a></li><li class="nav-item"><a class="nav-link" href="/language/modifier-reference">Reference</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-9" href="#sidenav-1-9" role="button" aria-expanded="false" aria-controls="sidenav-1-9">Concurrency</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-9"><li class="nav-item"><a class="nav-link" href="/language/concurrency">Overview</a></li><li class="nav-item"><a class="nav-link" href="/language/async">Asynchronous support</a></li><li class="nav-item"><a class="nav-link" href="/language/isolates">Isolates</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-1-10" href="#sidenav-1-10" role="button" aria-expanded="false" aria-controls="sidenav-1-10">Null safety</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-1-10"><li class="nav-item"><a class="nav-link" href="/null-safety">Sound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/migration-guide">Migrating to null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/understanding-null-safety">Understanding null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/unsound-null-safety">Unsound null safety</a></li><li class="nav-item"><a class="nav-link" href="/null-safety/faq">FAQ</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-2" role="button" aria-expanded="false" aria-controls="sidenav-2">Core libraries</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2"><li class="nav-item"><a class="nav-link" href="/libraries">Overview</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-core">dart:core</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-async">dart:async</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-math">dart:math</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-convert">dart:convert</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-io">dart:io</a></li><li class="nav-item"><a class="nav-link" href="/libraries/dart-html">dart:html</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/libraries/collections/iterables">Iterable collections</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-2-10" href="#sidenav-2-10" role="button" aria-expanded="false" aria-controls="sidenav-2-10">Asynchronous programming</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-2-10"><li class="nav-item"><a class="nav-link" href="/libraries/async/async-await">Tutorial</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/futures-error-handling">Futures and error handling</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/using-streams">Using streams</a></li><li class="nav-item"><a class="nav-link" href="/libraries/async/creating-streams">Creating streams</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-3" role="button" aria-expanded="false" aria-controls="sidenav-3">Effective Dart</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-3"><li class="nav-item"><a class="nav-link" href="/effective-dart">Overview</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/style">Style</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/documentation">Documentation</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/effective-dart/design">Design</a></li></ul></li><li class="nav-item"><a class="nav-link active collapsible" data-toggle="collapse" href="#sidenav-4" role="button" aria-expanded="true" aria-controls="sidenav-4">Packages</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-4"><li class="nav-item"><a class="nav-link" href="/tools/pub/packages">How to use packages</a></li><li class="nav-item"><a class="nav-link" href="/resources/useful-packages">Commonly used packages</a></li><li class="nav-item"><a class="nav-link active" href="/guides/libraries/create-packages">Creating packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/publishing">Publishing packages</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/writing-package-pages">Writing package pages</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-4-6" href="#sidenav-4-6" role="button" aria-expanded="false" aria-controls="sidenav-4-6">Package reference</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-4-6"><li class="nav-item"><a class="nav-link" href="/tools/pub/dependencies">Dependencies</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/package-layout">Package layout conventions</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/environment-variables">Pub environment variables</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/pubspec">Pubspec file</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/troubleshoot">Troubleshooting pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/verified-publishers">Verified publishers</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/security-advisories">Security advisories</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/versioning">Versioning</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/custom-package-repositories">Custom package repositories</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/libraries/private-files">What not to commit</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-5" role="button" aria-expanded="false" aria-controls="sidenav-5">Development</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5"><li class="nav-item"><a class="nav-link" href="/guides/json">JSON</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/numbers">Number representation</a></li><li class="nav-item"><a class="nav-link" href="/resources/google-apis">Google APIs</a></li><li class="nav-item"><a class="nav-link" href="/multiplatform-apps">Multi-platform apps</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-5" href="#sidenav-5-5" role="button" aria-expanded="false" aria-controls="sidenav-5-5">Command-line & server apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-5"><li class="nav-item"><a class="nav-link" href="/server">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/cmdline">Write command-line apps</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/fetch-data">Fetch data from the internet</a></li><li class="nav-item"><a class="nav-link" href="/tutorials/server/httpserver">Write HTTP servers</a></li><li class="nav-item"><a class="nav-link" href="/server/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/server/google-cloud">Google Cloud</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-5-6" href="#sidenav-5-6" role="button" aria-expanded="false" aria-controls="sidenav-5-6">Web apps</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-5-6"><li class="nav-item"><a class="nav-link" href="/web">Overview</a></li><li class="nav-item"><a class="nav-link" href="/web/get-started">Get started</a></li><li class="nav-item"><a class="nav-link" href="/web/deployment">Deployment</a></li><li class="nav-item"><a class="nav-link" href="/web/libraries">Libraries & packages</a></li><li class="nav-item"><a class="nav-link" href="/web/wasm">Wasm compilation</a></li></ul></li><li class="nav-item"><a class="nav-link" href="/guides/environment-declarations">Environment declarations</a></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-6" role="button" aria-expanded="false" aria-controls="sidenav-6">Interoperability</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6"><li class="nav-item"><a class="nav-link" href="/interop/c-interop">C interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/objective-c-interop">Objective-C & Swift interop</a></li><li class="nav-item"><a class="nav-link" href="/interop/java-interop">Java & Kotlin interop</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-6-4" href="#sidenav-6-4" role="button" aria-expanded="false" aria-controls="sidenav-6-4">JavaScript interop</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-6-4"><li class="nav-item"><a class="nav-link" href="/interop/js-interop">Overview</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/usage">Usage</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/js-types">JS types</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/tutorials">Tutorials</a></li><li class="nav-item"><a class="nav-link" href="/interop/js-interop/past-js-interop">Past JS interop</a></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/interop/js-interop/package-web">Web interop</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-7" role="button" aria-expanded="false" aria-controls="sidenav-7">Tools & techniques</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7"><li class="nav-item"><a class="nav-link" href="/tools">Overview</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2" href="#sidenav-7-2" role="button" aria-expanded="false" aria-controls="sidenav-7-2">Editors & debuggers</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2"><li class="nav-item"><a class="nav-link" href="/tools/jetbrains-plugin">IntelliJ & Android Studio</a></li><li class="nav-item"><a class="nav-link" href="/tools/vs-code">VS Code</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-devtools">Dart DevTools</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-2-4" href="#sidenav-7-2-4" role="button" aria-expanded="false" aria-controls="sidenav-7-2-4">DartPad</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-2-4"><li class="nav-item"><a class="nav-link" href="/tools/dartpad">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartpad/troubleshoot">Troubleshooting DartPad</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-3" href="#sidenav-7-3" role="button" aria-expanded="false" aria-controls="sidenav-7-3">Command-line tools</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-3"><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-1" href="#sidenav-7-3-1" role="button" aria-expanded="true" aria-controls="sidenav-7-3-1">Dart SDK</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-1"><li class="nav-item"><a class="nav-link" href="/tools/sdk">Overview</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-tool">dart</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-analyze">dart analyze</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-compile">dart compile</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-create">dart create</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-doc">dart doc</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-fix">dart fix</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-format">dart format</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-info">dart info</a></li><li class="nav-item"><a class="nav-link" href="/tools/pub/cmd">dart pub</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-run">dart run</a></li><li class="nav-item"><a class="nav-link" href="/tools/dart-test">dart test</a></li><li class="nav-item"><a class="nav-link" href="/tools/dartaotruntime">dartaotruntime</a></li><li class="nav-item"><a class="nav-link" href="/tools/experiment-flags">Experiment flags</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" data-target="#sidenav-7-3-2" href="#sidenav-7-3-2" role="button" aria-expanded="true" aria-controls="sidenav-7-3-2">Other command-line tools</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-7-3-2"><li class="nav-item"><a class="nav-link" href="/tools/build_runner">build_runner</a></li><li class="nav-item"><a class="nav-link" href="/tools/webdev">webdev</a></li></ul></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-4" href="#sidenav-7-4" role="button" aria-expanded="false" aria-controls="sidenav-7-4">Static analysis</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-4"><li class="nav-item"><a class="nav-link" href="/tools/analysis">Customizing static analysis</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/sound-problems">Fixing common type problems</a></li><li class="nav-item"><a class="nav-link" href="/tools/non-promotion-reasons">Fixing type promotion failures</a></li><li class="nav-item"><a class="nav-link" href="/tools/linter-rules">Linter rules</a></li><li class="nav-item"><a class="nav-link" href="/tools/diagnostic-messages">Diagnostic messages</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-7-5" href="#sidenav-7-5" role="button" aria-expanded="false" aria-controls="sidenav-7-5">Testing & optimization</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-7-5"><li class="nav-item"><a class="nav-link" href="/guides/testing">Testing</a></li><li class="nav-item"><a class="nav-link" href="/web/debugging">Debugging web apps</a></li></ul></li></ul></li><li aria-hidden="true"><div class="sidebar-primary-divider"></div></li><li class="nav-item"><a class="nav-link collapsed collapsible" data-toggle="collapse" href="#sidenav-9" role="button" aria-expanded="false" aria-controls="sidenav-9">Resources</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9"><li class="nav-item"><a class="nav-link" href="/resources/dart-cheatsheet">Language cheatsheet</a></li><li class="nav-item"><a class="nav-link" href="/resources/breaking-changes">Breaking changes</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/evolution">Language evolution</a></li><li class="nav-item"><a class="nav-link" href="/guides/language/spec">Language specification</a></li><li class="nav-item"><a class="nav-link" href="/resources/dart-3-migration">Dart 3 migration guide</a></li><li class="nav-item"><a class="nav-link collapsible collapsed" data-toggle="collapse" data-target="#sidenav-9-6" href="#sidenav-9-6" role="button" aria-expanded="false" aria-controls="sidenav-9-6">Coming from ...</a><ul class="nav flex-column flex-nowrap collapse" id="sidenav-9-6"><li class="nav-item"><a class="nav-link" href="/resources/coming-from/js-to-dart">JavaScript to Dart</a></li><li class="nav-item"><a class="nav-link" href="/resources/coming-from/swift-to-dart">Swift to Dart</a></li></ul></li><div class="dropdown-divider"></div><li class="nav-item"><a class="nav-link" href="/resources/faq">FAQ</a></li><li class="nav-item"><a class="nav-link" href="/resources/glossary">Glossary</a></li><li class="nav-item"><a class="nav-link" href="/resources/books">Books</a></li><li class="nav-item"><a class="nav-link" href="/resources/videos">Videos</a></li><li class="nav-item"><a class="nav-link" href="/tutorials">Tutorials</a></li></ul></li><li class="nav-item"><a class="nav-link collapsible" data-toggle="collapse" href="#sidenav-10" role="button" aria-expanded="true" aria-controls="sidenav-10">Related sites</a><ul class="nav flex-column flex-nowrap collapse show" id="sidenav-10"><li class="nav-item"><a class="nav-link" href="https://api.dart.dev" target="_blank" rel="noopener">API reference</a></li><li class="nav-item"><a class="nav-link" href="https://medium.com/dartlang" target="_blank" rel="noopener">Blog</a></li><li class="nav-item"><a class="nav-link" href="https://dartpad.dev" target="_blank" rel="noopener">DartPad (online editor)</a></li><li class="nav-item"><a class="nav-link" href="https://flutter.dev" target="_blank" rel="noopener">Flutter</a></li><li class="nav-item"><a class="nav-link" href="https://pub.dev" target="_blank" rel="noopener">Package site</a></li></ul></li></ul></div></div><main id="page-content"><div id="site-toc--side" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry nav-item"><a class="nav-link" href="#creating-a-new-package">Creating a new package</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#what-makes-a-package">What makes a package</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#organizing-a-package">Organizing a package</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#importing-library-files">Importing library files</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#conditionally-importing-and-exporting-library-files">Conditionally importing and exporting library files</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#providing-additional-files">Providing additional files</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#documenting-a-library">Documenting a library</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#distributing-a-library">Distributing an open source library</a></li><li class="toc-entry nav-item"><a class="nav-link" href="#resources">Resources</a></li></ul></div><article><div class="content"><div id="site-content-title"><h1>Creating packages</h1></div><div id="site-toc--inline" class="site-toc"><header class="site-toc__title">Contents</header><ul class="section-nav"><li class="toc-entry"><a href="#creating-a-new-package">Creating a new package</a></li><li class="toc-entry"><a href="#what-makes-a-package">What makes a package</a></li><li class="toc-entry"><a href="#organizing-a-package">Organizing a package</a></li><li class="toc-entry"><a href="#importing-library-files">Importing library files</a></li><li class="toc-entry"><a href="#conditionally-importing-and-exporting-library-files">Conditionally importing and exporting library files</a></li><li class="toc-entry"><a href="#providing-additional-files">Providing additional files</a></li><li class="toc-entry"><a href="#documenting-a-library">Documenting a library</a></li><li class="toc-entry"><a href="#distributing-a-library">Distributing an open source library</a></li><li class="toc-entry"><a href="#resources">Resources</a></li></ul></div><p>The Dart ecosystem uses <a href="/tools/pub/packages">packages</a> to share software such as libraries and tools. This page tells you how to create a standard shared <a href="/tools/pub/glossary#package">package</a>.</p><div class="header-wrapper"><h2 id="creating-a-new-package">Creating a new package</h2><a class="heading-link" href="#creating-a-new-package" aria-label="Link to 'Creating a new package' section">#</a></div><p>To create the initial directory and structure for a package, use the <a href="/tools/dart-create"><code>dart create</code></a> command and the <code>package</code> template:</p><div class="code-block-wrapper language-console"><div class="code-block-body"><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#222222">$ dart create -t package <PACKAGE_NAME></span></span></code></pre></div></div><div class="header-wrapper"><h2 id="what-makes-a-package">What makes a package</h2><a class="heading-link" href="#what-makes-a-package" aria-label="Link to 'What makes a package' section">#</a></div><p>The following diagram shows the simplest layout of a package:</p><p><img src="/assets/img/libraries/simple-lib2.png" alt="root directory contains pubspec.yaml and lib/file.dart"></p><p>The minimal requirements for a library are:</p><dl><dt>pubspec file</dt><dd>The <code>pubspec.yaml</code> file for a library is the same as for an <a href="/tools/pub/glossary#application-package">application package</a>—there is no special designation to indicate that the package is a library.</dd><dt>lib directory</dt><dd>As you might expect, the library code lives under the <em>lib</em> directory and is public to other packages. You can create any hierarchy under lib, as needed. By convention, implementation code is placed under <em>lib/src</em>. Code under lib/src is considered private; other packages should never need to import <code>src/...</code>. To make APIs under lib/src public, you can export lib/src files from a file that's directly under lib.</dd></dl><div class="header-wrapper"><h2 id="organizing-a-package">Organizing a package</h2><a class="heading-link" href="#organizing-a-package" aria-label="Link to 'Organizing a package' section">#</a></div><p>Packages are easiest to maintain, extend, and test when you create small, individual libraries, referred to as <em>mini libraries</em>. In most cases, each class should be in its own mini library, unless you have a situation where two classes are tightly coupled.</p><aside class="alert alert-info"><div class="alert-header"><i class="material-symbols" aria-hidden="true">info</i> <span>Note</span></div><div class="alert-content"><p>You might know about the <code>part</code> directive. This directive allows you to split a library into multiple Dart files. Though part files can incorporate generated code into a library, the Dart team doesn't recommend using them. Instead, create small libraries.</p></div></aside><p>Create a "main" library file directly under lib, lib/<em><package-name></em>.dart, that exports all of the public APIs. This allows the user to get all of a library's functionality by importing a single file.</p><p>The lib directory might also include other importable, non-src, libraries. For example, perhaps your main library works across platforms, but you create separate libraries that rely on <code>dart:io</code> or <code>dart:js_interop</code>. Some packages have separate libraries that are meant to be imported with a prefix, when the main library is not.</p><p>Let's look at the organization of a real-world package: shelf. The <a href="https://github.com/dart-lang/shelf">shelf</a> package provides an easy way to create web servers using Dart, and is laid out in a structure that is commonly used for Dart packages:</p><p><img src="/assets/img/libraries/shelf.png" alt="shelf root directory contains example, lib, test, and tool subdirectories"></p><p>Directly under lib, the main library file, <code>shelf.dart</code>, exports API from several files in <code>lib/src</code>. To avoid exposing more API than intended—and to give developers an overview of the entire public API of the package—<code>shelf.dart</code> uses <code>show</code> to specify exactly which symbols to export:</p><div class="code-block-wrapper language-dart"><div class="code-block-header">lib/shelf.dart</div><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/cascade.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Cascade;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/handler.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Handler;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/hijack_exception.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> HijackException;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/middleware.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Middleware, createMiddleware;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/middleware/add_chunked_encoding.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> addChunkedEncoding;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/middleware/logger.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> logRequests;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/middleware_extensions.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> MiddlewareExtensions;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/pipeline.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Pipeline;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/request.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Request;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/response.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Response;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/server.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> Server;</span></span> <span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/server_handler.dart'</span><span style="color:#D43324"> show</span><span style="color:#222222"> ServerHandler;</span></span></code></pre></div></div><p>The shelf package also contains a mini library: shelf_io. This adapter handles HttpRequest objects from <code>dart:io</code>.</p><aside class="alert alert-success"><div class="alert-header"><i class="material-symbols" aria-hidden="true">lightbulb</i> <span>Tip</span></div><div class="alert-content"><p>For the best performance when developing with the development JavaScript compiler through <a href="/tools/webdev#serve"><code>webdev serve</code></a>, put <a href="/tools/pub/package-layout#implementation-files">implementation files</a> under <code>/lib/src</code>, instead of elsewhere under <code>/lib</code>. Also, avoid imports of <code>package:<em>package_name</em>/src/...</code>.</p></div></aside><div class="header-wrapper"><h2 id="importing-library-files">Importing library files</h2><a class="heading-link" href="#importing-library-files" aria-label="Link to 'Importing library files' section">#</a></div><p>When importing a library file from another package, use the <code>package:</code> directive to specify the URI of that file.</p><div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">import</span><span style="color:#11796D"> 'package:utilities/utilities.dart'</span><span style="color:#222222">;</span></span></code></pre></div></div><p>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. Use <code>package:</code> when the imported file is in lib and the importer is outside.</p><p>The following graphic shows how to import <code>lib/foo/a.dart</code> from both lib and web.</p><p><img src="/assets/img/libraries/import-lib-rules.png" alt="lib/bar/b.dart uses a relative import; web/main.dart uses a package import"></p><div class="header-wrapper"><h2 id="conditionally-importing-and-exporting-library-files">Conditionally importing and exporting library files</h2><a class="heading-link" href="#conditionally-importing-and-exporting-library-files" aria-label="Link to 'Conditionally importing and exporting library files' section">#</a></div><p>If your library supports multiple platforms, then you might need to conditionally import or export library files. A common use case is a library that supports both web and native platforms.</p><p>To conditionally import or export, you need to check for the presence of <code>dart:*</code> libraries. Here's an example of conditional export code that checks for the presence of <code>dart:io</code> and <code>dart:js_interop</code>:</p> <?code-excerpt "create_libraries/lib/hw_mp.dart (export)"?> <div class="code-block-wrapper language-dart"><div class="code-block-header">lib/hw_mp.dart</div><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">export</span><span style="color:#11796D"> 'src/hw_none.dart'</span><span style="color:#6E6E70"> // Stub implementation</span></span> <span class="line"><span style="color:#D43324"> if</span><span style="color:#222222"> (dart.library.io) </span><span style="color:#11796D">'src/hw_io.dart'</span><span style="color:#6E6E70"> // dart:io implementation</span></span> <span class="line"><span style="color:#D43324"> if</span><span style="color:#222222"> (dart.library.js_interop) </span><span style="color:#11796D">'src/hw_web.dart'</span><span style="color:#222222">; </span><span style="color:#6E6E70">// package:web implementation</span></span></code></pre></div></div><p>Here's what that code does:</p><ul><li>In an app that can use <code>dart:io</code> (for example, a command-line app), export <code>src/hw_io.dart</code>.</li><li>In an app that can use <code>dart:js_interop</code> (a web app), export <code>src/hw_web.dart</code>.</li><li>Otherwise, export <code>src/hw_none.dart</code>.</li></ul><p>To conditionally import a file, use the same code as above, but change <code>export</code> to <code>import</code>.</p><aside class="alert alert-info"><div class="alert-header"><i class="material-symbols" aria-hidden="true">info</i> <span>Note</span></div><div class="alert-content"><p>The conditional import or export checks only whether the library is <em>available for use</em> on the current platform, not whether it's actually imported or used.</p></div></aside><p>All of the conditionally exported libraries must implement the same API. For example, here's the <code>dart:io</code> implementation:</p> <?code-excerpt "create_libraries/lib/src/hw_io.dart"?> <div class="code-block-wrapper language-dart"><div class="code-block-header">lib/src/hw_io.dart</div><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">import</span><span style="color:#11796D"> 'dart:io'</span><span style="color:#222222">;</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> alarm</span><span style="color:#222222">([</span><span style="color:#0468D7">String</span><span style="color:#222222">? text]) {</span></span> <span class="line"><span style="color:#222222"> stderr.</span><span style="color:#6200EE">writeln</span><span style="color:#222222">(text ?? message);</span></span> <span class="line"><span style="color:#222222">}</span></span> <span class="line"></span> <span class="line"><span style="color:#0468D7">String</span><span style="color:#D43324"> get</span><span style="color:#222222"> message => </span><span style="color:#11796D">'Hello World from the VM!'</span><span style="color:#222222">;</span></span></code></pre></div></div><p>And here's the default implementation, which uses stubs that throw <code>UnsupportedError</code>:</p> <?code-excerpt "create_libraries/lib/src/hw_none.dart"?> <div class="code-block-wrapper language-dart"><div class="code-block-header">lib/src/hw_none.dart</div><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> alarm</span><span style="color:#222222">([</span><span style="color:#0468D7">String</span><span style="color:#222222">? text]) => </span><span style="color:#D43324">throw</span><span style="color:#0468D7"> UnsupportedError</span><span style="color:#222222">(</span><span style="color:#11796D">'hw_none alarm'</span><span style="color:#222222">);</span></span> <span class="line"></span> <span class="line"><span style="color:#0468D7">String</span><span style="color:#D43324"> get</span><span style="color:#222222"> message => </span><span style="color:#D43324">throw</span><span style="color:#0468D7"> UnsupportedError</span><span style="color:#222222">(</span><span style="color:#11796D">'hw_none message'</span><span style="color:#222222">);</span></span></code></pre></div></div><p>On any platform, you can import the library that has the conditional export code:</p> <?code-excerpt "create_libraries/example/hw_example.dart" replace="/create_libraries/hw_mp/g"?> <div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#D43324">import</span><span style="color:#11796D"> 'package:hw_mp/hw_mp.dart'</span><span style="color:#222222">;</span></span> <span class="line"></span> <span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> main</span><span style="color:#222222">() {</span></span> <span class="line"><span style="color:#6200EE"> print</span><span style="color:#222222">(message);</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><div class="header-wrapper"><h2 id="providing-additional-files">Providing additional files</h2><a class="heading-link" href="#providing-additional-files" aria-label="Link to 'Providing additional files' section">#</a></div><p>A well-designed package is easy to test. We recommend that you write tests using the <a href="https://github.com/dart-lang/test">test</a> package, placing the test code in the <code>test</code> directory at the top of the package.</p><p>If you create any command-line tools intended for public consumption, place those in the <code>bin</code> directory, which is public. Enable running a tool from the command line, using <a href="/tools/pub/cmd/pub-global#activating-a-package"><code>dart pub global activate</code></a>. Listing the tool in the <a href="/tools/pub/pubspec#executables"><code>executables</code> section</a> of the pubspec allows a user to run it directly without calling <a href="/tools/pub/cmd/pub-global#running-a-script-using-dart-pub-global-run"><code>dart pub global run</code></a>.</p><p>It's helpful if you include an example of how to use your library. This goes into the <code>example</code> directory at the top of the package.</p><p>Any tools or executables that you create during development that aren't for public use go into the <code>tool</code> directory.</p><p>Other files that are required if you publish your library to the <a href="https://pub.dev">pub.dev</a> site, such as <code>README.md</code> and <code>CHANGELOG.md</code>, are described in <a href="/tools/pub/publishing">Publishing a package</a>. For more information on how to organize a package directory, see the <a href="/tools/pub/package-layout">pub package layout conventions</a>.</p><div class="header-wrapper"><h2 id="documenting-a-library">Documenting a library</h2><a class="heading-link" href="#documenting-a-library" aria-label="Link to 'Documenting a library' section">#</a></div><p>You can generate API docs for your library using the <a href="/tools/dart-doc"><code>dart doc</code></a> tool. <code>dart doc</code> parses the source looking for <a href="/effective-dart/documentation#doc-comments">documentation comments</a>, which use the <code>///</code> syntax:</p><div class="code-block-wrapper language-dart"><div class="code-block-body"><span class="code-block-language" title="Language dart">dart</span><pre class="shiki dash-light" tabindex="0"><code><span class="line"><span style="color:#6E6E70">/// The event handler responsible for updating the badge in the UI.</span></span> <span class="line"><span style="color:#D43324">void</span><span style="color:#6200EE"> updateBadge</span><span style="color:#222222">() {</span></span> <span class="line"><span style="color:#222222"> ...</span></span> <span class="line"><span style="color:#222222">}</span></span></code></pre></div></div><p>For an example of generated docs, see the <a href="https://pub.dev/documentation/shelf/latest">shelf documentation.</a></p><p>To include any <em>library-level</em> documentation in the generated docs, add a <code>library</code> directive and attach the comment directly above it. For the how-and-why of documenting libraries, see <a href="/effective-dart/documentation#consider-writing-a-library-level-doc-comment">Effective Dart: Documentation</a>.</p><div class="header-wrapper"><h2 id="distributing-a-library">Distributing an open source library</h2><a class="heading-link" href="#distributing-a-library" aria-label="Link to 'Distributing an open source library' section">#</a></div><p>If your library is open source, we recommend sharing it on the <a href="https://pub.dev">pub.dev site.</a> To publish or update the library, use <a href="/tools/pub/cmd/pub-lish">pub publish</a>, which uploads your package and creates or updates its page. For example, see the page for the <a href="https://pub.dev/packages/shelf">shelf package.</a> See <a href="/tools/pub/publishing">Publishing a package</a> for details on how to prepare your package for publishing.</p><p>The pub.dev site not only hosts your package, but also generates and hosts your package's API reference docs. A link to the latest generated docs is in the package's <strong>About</strong> box; for example, see the shelf package's <a href="https://pub.dev/documentation/shelf">API docs.</a> Links to previous versions' docs are in the <strong>Versions</strong> tab of the package's page.</p><p>To ensure that your package's API docs look good on the pub.dev site, follow these steps:</p><ul><li>Before publishing your package, run the <a href="/tools/dart-doc"><code>dart doc</code></a> tool to make sure that your docs generate successfully and look as expected.</li><li>After publishing your package, check the <strong>Versions</strong> tab to make sure that the docs generated successfully.</li><li>If the docs didn't generate at all, click <strong>failed</strong> in the <strong>Versions</strong> tab to see the <code>dart doc</code> output.</li></ul><div class="header-wrapper"><h2 id="resources">Resources</h2><a class="heading-link" href="#resources" aria-label="Link to 'Resources' section">#</a></div><p>Use the following resources to learn more about packages:</p><ul><li><a href="/language/libraries">Libraries and imports</a> covers using library files.</li><li>The <a href="/tools/pub/packages">package</a> documentation is useful, particularly the <a href="/tools/pub/package-layout">package layout conventions</a>.</li><li><a href="private-files">What not to commit</a> covers what should not be checked into a source code repository.</li><li>The newer packages under the <a href="https://github.com/dart-lang">dart-lang</a> organization tend to show best practices. Consider studying these examples: <a href="https://github.com/dart-lang/dart_style">dart_style,</a> <a href="https://github.com/dart-lang/path">path,</a> <a href="https://github.com/dart-lang/shelf">shelf,</a> <a href="https://github.com/dart-lang/source_gen">source_gen,</a> and <a href="https://github.com/dart-lang/test">test.</a></li></ul><p id="page-github-links"><span>Unless stated otherwise, the documentation on this site reflects Dart 3.5.4. Page last updated on 2024-11-18.</span> <a href="https://github.com/dart-lang/site-www/tree/main/src/content/guides/libraries/create-packages.md" target="_blank" rel="noopener">View source</a> <span>or </span><a href="https://github.com/dart-lang/site-www/issues/new?template=1_page_issue.yml&page-url=https://dart.dev/guides/libraries/create-packages/&page-source=https://github.com/dart-lang/site-www/tree/main/src/content/guides/libraries/create-packages.md" title="Report an issue with this page" target="_blank" rel="noopener">report an issue</a>.</p></div></article></main><footer id="page-footer"><div class="footer-section footer-main"><a href="/" class="brand" title="Dart"><img src="/assets/img/logo/logo-white-text.svg" alt="Dart" width="164"></a><div class="footer-social-links"><a href="https://medium.com/dartlang" target="_blank" rel="noopener" title="Medium blog"><svg><use href="/assets/img/social/medium.svg#medium"></use></svg> </a><a href="https://github.com/dart-lang" target="_blank" rel="noopener" title="GitHub"><svg><use href="/assets/img/social/github.svg#github"></use></svg> </a><a href="https://twitter.com/dart_lang" target="_blank" rel="noopener" title="X (Twitter)"><svg><use href="/assets/img/social/x.svg#x"></use></svg></a></div></div><div class="footer-section footer-tray"><div class="footer-licenses">Except as otherwise noted, this site is licensed under a <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>, and code samples are licensed under the <a href="https://opensource.org/licenses/BSD-3-Clause">3-Clause BSD License</a>.</div><div class="footer-utility-links"><ul><li><a href="/terms" title="Terms of use">Terms</a></li><li><a href="https://policies.google.com/privacy" target="_blank" rel="noopener" title="Privacy policy">Privacy</a></li><li><a href="/security" title="Security philosophy and practices">Security</a></li></ul></div></div></footer></body></html>