Create a package in dart

6,285

Solution 1

To create a package named mypackage.

For Dart package:

dart  create --template=package-simple  mypackage

For Flutter package:

flutter create --template=package mypackage

Solution 2

From the Dart/Flutter Documentation:

Step 1: Create the package To create a Flutter package, use the --template=package flag with flutter create:

flutter create --template=package hello

This creates a package project in the hello folder with the following content:

LICENSE
A (mostly) empty license text file.

test/hello_test.dart
The unit tests for the package.

hello.iml
A configuration file used by the IntelliJ IDEs.

.gitignore
A hidden file that tells Git which files or folders to ignore in a project.

.metadata
A hidden file used by IDEs to track the properties of the Flutter project.

pubspec.yaml
A yaml file containing metadata that specifies the package’s dependencies. Used by the pub tool.

README.md
A starter markdown file that briefly describes the package’s purpose.

lib/hello.dart
A starter app containing Dart code for the package.

.idea/modules.xml, .idea/modules.xml, .idea/workspace.xml**
A hidden folder containing configuration files for the IntelliJ IDEs.

CHANGELOG.md
A (mostly) empty markdown file for tracking version changes to the package.

Solution 3

There's no such possibilty in the Dart Editor for now. To create a package follow these steps :

  • create an New Application mylib without sample content
  • add a pubspec.yaml file
  • add a lib folder
  • create a mylib.dart containing the code you want to package

See the Package layout conventions for more informations.

Share:
6,285
mc_fish
Author by

mc_fish

Updated on November 24, 2022

Comments

  • mc_fish
    mc_fish over 1 year

    How do I create a package in the new Dart Editor?

    There is no "Add Pub support" checkbox?

    Also how to create "packages" with the new editor?

    Is a tutorial out there that describes the process with the new Editor?