“This is the 15th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
Introduction to the
Pubspec. yaml is the soul of all DART projects. It contains dependency information and other meta information for all DART projects, so Pubspec. yaml is the META for DART projects!
Fields supported by pubspec.yaml
According to dart’s definition, pubspec.yaml can contain the following fields:
The field name | Required field | describe |
---|---|---|
name | is | The name of the package |
version | Yes if published to pub.dev | Version number of package |
description | Yes if published to pub.dev | Description of the package |
homepage | no | The package home page |
repository | no | The source code address of the package |
issue_tracker | no | Package problem trace address |
documentation | no | Documentation information for package |
dependencies | no | Dependency information for package |
dev_dependencies | no | Pacakge dev depends on information |
dependency_overrides | no | The package you want to override |
environment | Dart2 need | |
executables | no | Executable file path of package |
publish_to | no | How will the package be distributed |
Note that these are the fields supported by Pubspec. yaml in dart, but there are additional fields that are supported in the FLUTTER environment.
A case in point
Let’s look at a concrete example:
Name: my_app version: 11.15 description: >- this is a new app homepage: http://www.flydean.com documentation: http://www.flydean.com environment: SDK: '>=2.10.0 <3.0.0' dependencies: efts: ^2.0.4 transmogrify: ^0.4.0 dev_dependencies: test: '>=1.15.0 <2.0.0'Copy the code
The field details
Let’s look at the details and limitations of each field:
- Name
Name is the name of the package. The name must be all lowercase. If there are multiple words, you can distinguish them by underscores, for example, my_app.
Use only lowercase letters and numbers, do not start with a number, and do not use reserved words in DART.
- Version
Version indicates the Version number. The Version number is a three-digit number separated by dots, for example, 11.15.0. +1, +2, +hotfix. Oopsie, pre-release, etc. : -dev.4, -alpha.12, -beta.7, -rC.5.
- Description
The description of the package is best described in English. It contains 60 to 180 characters and indicates the function of the package.
- Dependencies
There are two types of dependency information. One is the dependencies that all people who use this package need to use. These dependencies are placed in dependencies.
There is also a package that is used only in the current development of Pacakge, which is placed in dev_dependencies.
In some cases, we may need to override some dependency packages, this can be in: dependency_overrides.
- Executables
Some Pacakges provide tools for you to use, which may be command-line tools, so you need to specify the path of commands that can be executed in executables.
For example:
executables:
slidy: main
fvm:
Copy the code
Dart and binfvm.dart can be executed globally by executing slidy to bin/main.dart and FVM to binfvm.dart after pub global activate.
- environment
Because Dart is a new language, it’s been a big change so far. So some applications can rely on different versions of dart, where environment is needed:
Environment: the SDK: '> = 2.10.0 < 3.0.0'Copy the code
In the code above, we specify the dart SDK version range.
Since dart1.19, environment: also supports versions that specify flutter:
Environment: SDK: '>=1.19.0 <3.0.0' flutter: ^0.1.2Copy the code
conclusion
That’s dart’s metaworld pubspec.yaml.
This article is available at www.flydean.com/10-dart-pub…
The most popular interpretation, the most profound dry goods, the most concise tutorial, many tips you didn’t know waiting for you to discover!
Welcome to pay attention to my public number: “procedures those things”, understand technology, more understand you!