6

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?

mc_fish
  • 493
  • 3
  • 10

6 Answers6

13

To create a package named mypackage.

For Dart package:

dart  create --template=package-simple  mypackage

For Flutter package:

flutter create --template=package mypackage
karel
  • 5,489
  • 46
  • 45
  • 50
X PersPective
  • 161
  • 1
  • 4
5

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.
Ride Sun
  • 2,145
  • 3
  • 18
  • 41
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.

Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132
  • i did all of that, if i install over pub => success but cant use it in other apps, if i deploy it (error no web folder) if i add the web folder it deploys but still cant use the package? – mc_fish Sep 02 '13 at 22:20
  • _pub install_ will not allow you to use it in other apps. This command only creates `packages` directory in several places to allow Dart files to run when dependencies are defined. See [pub install doc](https://pub.dartlang.org/doc/pub-install.html). Locally you can use a [path package](https://pub.dartlang.org/doc/dependencies.html#path-packages). – Alexandre Ardhuin Sep 03 '13 at 09:35
0

You can create a dart project following the flutter way that allow you to auto generate the structure and the hierarchy of the package.

Mohamed Dernoun
  • 776
  • 5
  • 13
0

Follow below steps to create a package in DART:

Step 1: Create the package

$ flutter create --template=package hello

Step 2: Implement the package

For pure Dart packages, simply add the functionality inside the main lib/.dart file, or in several files in the lib directory.

To test the package, add unit tests in a test directory.

For additional details on how to organize the package contents, see the Dart library package documentation: https://flutter.dev/docs/development/packages-and-plugins/developing-packages

ZealousWeb
  • 1,647
  • 1
  • 10
  • 11
  • interestingly you answered a question from 2013 for Dart 1...you are aware of that :D – mc_fish Dec 01 '21 at 07:53
  • It's a mistake to think of this as erroneously answering a question for Dart 1.0. New Dart users who want to know how to create a Dart library will come across this and be happy to find this up-to-date answer. What do they care that the question was originally asked in 2013? – AmigoNico Aug 29 '22 at 03:29
-1

Any dart app is a package. To create a new Dart app use:

dart create my_package
Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162