Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating your first Flutter Package

Creating your first Flutter Package

How to develop and publish Dart / Flutter packages

Danvick Miller

November 21, 2020
Tweet

More Decks by Danvick Miller

Other Decks in Programming

Transcript

  1. About me • Founder & CTO - Infinitysoft Tech •

    Co-organizer: DroidconKe & Flutter Developers Kenya • Web/Mobile Consultant • Passionate about cross-platform development. • Native Java Android ~ 2011-2012 • Intel XDK - 2013 • Ionic - 2016-2017 • NativeScript - 2017-18 • Flutter - August 2018
  2. Why Create a Package • Reusability • Community - sharing

    • Enhance your resume / profile • Learning
  3. How to get started • Dart packages - General packages

    written in Dart, for example the path package. May also depend on Flutter SDK • Plugin packages - specialized Dart package that contains an API written in Dart code combined with one or more platform- specific implementations. • Publish something that is likely to be used by other developers • Google account needed to publish to pub.dev
  4. Package structure my_package/ doc/ api/ *** getting_started.md example/ lib/ main.dart

    lib/ src/ my_package.dart test/ CHANGELOG.md LICENSE Pubspec.yaml README.md
  5. Pubspec file • name Required for every package. • version

    Required for packages that are hosted on the pub.dev site. • description Required for packages that are hosted on the pub.dev site. • homepage Optional. URL pointing to the package’s homepage (or source code repository). • repository Optional. URL pointing to the package’s source code repository. • issue_tracker Optional. URL pointing to an issue tracker for the package. • documentation Optional. URL pointing to documentation for the package. • dependencies Can be omitted if your package has no dependencies. • dev_dependencies Can be omitted if your package has no dev dependencies. • dependency_overrides Can be omitted if you do not need to override any dependencies. • environment Required as of Dart 2. Learn more. • executables Optional. Used to put a package’s executables on your PATH. • publish_to Optional. Specify where to publish a package. • Pub ignores all other fields,
  6. Package Metrics & Scoring • Likes: A measure of how

    many developers have liked a package. This provides a raw measure of the overall sentiment of a package from peer developers. • Pub Points: Measurement of quality such as code style, platform support, and maintainability. • Popularity: How many developers use your package - usually the number of apps that depend on a package over the past 60 days.
  7. Getting the maximum Pub Points • Follow Dart file conventions:

    Provide pubspec.yaml, LICENSE, README.md, CHANGELOG.md • Provide documentation & example • Support multiple platforms • Pass static analysis: check if package contains any errors, warnings, and lints (code style issues) • Support up-to-date dependencies: Dart SDK, Flutter SDK, package/plugin dependncies
  8. Publishing checklist • Confirm LICENSE file • Check README.MD •

    Update pubspec.yaml to have latest version to be published • Update CHANGELOG.md • flutter analyze or dart analyze • flutter format lib • flutter format test (optional) • flutter formart exampe (optional) • dartdoc (optional) • pub publish --dry-run • pub publish
  9. Misc. • Testing • analysis_options.yaml - Dart analyzer settings •

    Semver • Tag versions • Dependency overrides • Github - issues, versions, PRs (MRs) • Verified publishers