Dart Package vs Plugin Package
Dart packages: Only packages are written using Flutter and Dart SDKs independent of native platforms such which are Android and iOS. The meet_network_image package is an example of a Dart package.
Plugin packages: A special Dart package for Android (using Java or Kotlin) and/or iOS (using ObjC or Swift) platform-specific application that includes an API written in the Dart code. The image_picker plugin allows you to take pictures or retrieve an existing image from your gallery using separate APIs for iOS and Android.
Creating Dart Package
Open the command line in your operating system, and type the following line with your
flutter create --template=package package_name
If you are using an IntelliJ IDEA or Android Studio, you can convert the project type to a package when creating a Flutter project.
Let’s put your project to the GitHub
After opening a repository via Github, you can upload these commands one by one from the directory where your project is located to Github, remember to enter your own remote address!
git add --all
git commit -m "initial commit"
git remote add origin https://github.com/onatcipli/custom_alert_box.git
git push -u origin master
After pushing all project files to GitHub repository, We can begin with editing pubspec.yaml.
This is how our project files look like, lib/ is the folder that we will create and write the package codes
(In Step 3)
Let's begin with editing
In the description part, you can write a brief description of the package and what the package does.
In the author part, you need to write to people who support this package by using the following pattern
In the homepage part, you can enter the package repository URL
As you can see at the following part, we’ll list the changes in our package one by one in the changelog.md file.
## [version] - Date* explanations about changes.
## [0.0.1] - 2019-06-15
* A description for people who will use that package or version.
I will use MIT LICENSE, you only need to write your name and the year
Copyright © [year] [fullname]
Copyright (c) 2019 Onat ÇipliPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Step 3 (Writing package code /lib)
Now it’s time for implementing our dart package code,
We will delete the codes inside the
custom_alert_box.dart file, to be able to create our code. (You need to fix test folder when you delete the code inside the
custom_alert_box.dart, you can comment on the tests for now)
I just create a
CustomAlertBox class, and inside that class, I create a static method named
showCustomAlertBox to be able to show an alert box with using our package.
Our package should include example project which using our Dart package code with help of that example project you can easily test your package code, by the way, is an example for other users to learn how to use your package.
In our package directory,
We are creating a new Flutter project in our Dart Package directory as bellow and inside the example project inside the
pubspec.yaml file we need to add our package like following,
sdk: flutter custom_alert_box:
After that point, we able to import our package and use it in the example project.
Step 5(Publish package)
Before this step we need to push all changes to GitHub remote.
We able to publish our package to pub.dev with the following command,
flutter packages pub publish
After that, Command line gives you a link to verify your E-mail and pub.dev send you a mail about your package,
Dear package maintainer,
For details, go to https://pub.dev/packages/custom_alert_box/versions/0.0.1
If you have any concerns about this package, file an issue at
Thanks for your contributions to the Dart community!
With appreciation, the Dart package site admin
Every time you make changes in your package, you can publish the new version with
flutter packages pub publish but you need to push all the changes to GitHub and do not forget to write the changes to your