Mobile Development 9 min read

Creating, Publishing, and Using Flutter Packages and Plugins

This article explains what Flutter packages and plugins are, how to create them via IDE or command line, the required file structure, how to publish them to pub.dev, private registries or Git, and how to add them as dependencies in a Flutter project while also covering common troubleshooting steps.

TAL Education Technology
TAL Education Technology
TAL Education Technology
Creating, Publishing, and Using Flutter Packages and Plugins

During a recent mobile‑app refactor the team chose Flutter for its UI productivity, but some features require native code; sharing those features as reusable packages or plugins avoids duplicated effort across projects.

A Flutter package is a modular piece of code that can be easily shared; at minimum it contains a pubspec.yaml file with metadata and a lib folder with a public Dart file.

There are two main types: a Flutter Package (pure Dart, often providing widgets) and a Flutter Plugin (a Dart package that also includes platform‑specific implementations for Android and iOS).

Packages can be created either through the visual UI of Android Studio (Create New Flutter Project → select Flutter Package or Flutter Plugin, set name, language, etc.) or via the command line. Example commands are:

flutter create --template=package my_dart_package
flutter create --org com.example --template=plugin --platforms=android,ios -a kotlin -i swift my_plugin_package

The file structure of a pure Dart package typically includes LICENSE , README.md , CHANGELOG.md , pubspec.yaml , test/ , and lib/your_package.dart . A plugin adds platform folders such as android/src/main/java/.../FlutterPlugin , ios/Classes/FlutterPlugin.m , and an example/ app.

To publish a package you can choose pub.dev, a private Pub repository, or a Git repository. Before publishing, ensure pubspec.yaml , README.md , and CHANGELOG.md are complete. Typical fields in pubspec.yaml include name , version , description , homepage , optional publish_to , and author . Run a dry‑run with flutter packages pub publish --dry-run and publish with flutter packages pub publish .

After publishing, add the package to a project by declaring a dependency in pubspec.yaml . Version constraints can be exact, range, or open‑ended. Dependencies can also be fetched from Git, a private hosted server, or a local path, e.g.:

# from pub.dev
flutter_plugin: ^1.4.0
# from Git
flutter_plugin:
  git:
    url: https://github.com/xxxx/xxxx.git
    ref: '1.0.0'
# from private host
xes_recorder:
  hosted:
    name: xes_recorder
    url: http://pub.100tal.com
  version: 0.0.1
# local path
flutter_pub:
  path: ../

Common publishing issues include author warnings during dry‑run, Google authentication prompts, and snapshot conflicts. Work‑arounds involve using a custom mypub.dart.snapshot file and temporarily disabling Google auth, but remember to restore the original snapshot after publishing.

DartFluttermobile developmentpluginpackagepub
TAL Education Technology
Written by

TAL Education Technology

TAL Education is a technology-driven education company committed to the mission of 'making education better through love and technology'. The TAL technology team has always been dedicated to educational technology research and innovation. This is the external platform of the TAL technology team, sharing weekly curated technical articles and recruitment information.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.