The website provides a comprehensive guide on how to create, publish, and manage Flutter packages, distinguishing between Dart packages and plugin packages.
Abstract
The provided content is a detailed tutorial on developing and managing packages for the Flutter framework. It differentiates between Dart packages, which are platform-independent and written purely in Dart, and plugin packages, which offer APIs for platform-specific code. The guide walks through the process of creating a Dart package using the command line or an IDE like IntelliJ IDEA or Android Studio, version controlling the package with GitHub, editing the pubspec.yaml file, maintaining a CHANGELOG.md, selecting an appropriate license, and implementing the package code in the lib directory. It also emphasizes the importance of including an example project within the package to demonstrate usage and facilitate testing. Finally, the tutorial covers the steps to publish the package to pub.dev and manage subsequent updates, including incrementing the version number and documenting changes in the changelog.
Opinions
The author, Onat Çipli, advocates for the inclusion of a CHANGELOG.md file to document package updates in a structured manner.
The use of GitHub for version control and distribution is presented as a standard practice in the development workflow.
The tutorial suggests that choosing an open-source license, such as the MIT License, is a straightforward process that encourages community contributions and usage.
The author emphasizes the value of providing an example project within the package repository to serve as both a testing ground and a learning resource for users.
The author encourages developers to engage with the Flutter community by following relevant social media accounts and sharing their work on platforms like Twitter and LinkedIn.
How to Create, Publish and Manage Flutter Packages
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
Step 1
Open the command line in your operating system, and type the following line with your package_name
flutter create --template=packagepackage_name
OR
If you are using an IntelliJ IDEA or Android Studio, you can convert the project type to a package when creating a Flutter project.
Step 2
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!
Permission is hereby granted, free of charge, toany person obtaining a copy
of this software and associated documentation files (the"Software"), to deal
inthe Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies ofthe Software, andto permit persons to whom the Software is
furnished todo so, subject tothe 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
SOFTWARE.
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.
Step 4
Creating Example
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,
C:\Users\msi\IdeaProjects\custom_alert_box
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,
...
dependencies: flutter: sdk: flutter
custom_alert_box: path: ../
...
After that point, we able to import our package and use it in the example project.
Thanks for your contributions to the Dart community!
With appreciation, the Dart package site admin
Managing Package
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 CHANGELOG.md, change pubspec.yaml version