Just The Steps

  1. In the terminal, run the following command
flutter create --template=package my_package
  1. Make your changes in the lib directory
  2. 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
  1. 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: ../
  1. Run the following command to perform a dry run of publishing your package
flutter pub publish --dry-run
  1. 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.

Resources