Just The Steps
- In the terminal, run the following command
flutter create --template=package my_package
- Make your changes in the
lib
directory - Update the
pubspec.yaml
file with your package information. Here’s an example:
name: my_package
description: A new Flutter package
version: 0.0.1
homepage: https://example.com
repository:
type: git
url: https://github.com/me/example
- Create an
example
directory with a sample Flutter app that demonstrates how to use your package
flutter create example --empty
Inside the pubspec.yaml
file in the example
directory, add the following:
dependencies:
my_package:
path: ../
- Run the following command to perform a dry run of publishing your package
flutter pub publish --dry-run
- Run the following command to publish your package
flutter pub publish
Reusable Tasks
In VS Code, you can create a new tasks.json
file in the .vscode
folder with the following content:
{
"version": "2.0.0",
"tasks": [
{
"label": "Dry Run",
"type": "shell",
"command": "flutter pub publish --dry-run",
"problemMatcher": []
},
{
"label": "Publish",
"type": "shell",
"command": "flutter pub publish",
"problemMatcher": []
}
]
}
With this setup, you should be able to run the tasks from the command palette by typing Tasks: Run Task
and selecting the task you want to run.