Create a package in dart

8.9k Views Asked by At

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?

6

There are 6 best solutions below

2
On

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.

0
On

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

dart create my_package
0
On

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.
2
On

To create a package named mypackage.

For Dart package:

dart  create --template=package-simple  mypackage

For Flutter package:

flutter create --template=package mypackage
2
On

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

0
On

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