Specifying dependencies

Now that you know how the pub tool resolves packages inside the project, let's take a look at how to add dependencies to it.

Dependencies are specified in the dependencies field of the pubspec file. It is a YAML list field, so you can specify as many as needed in the field. Let's suppose that we need the json_serializable package in our project. We can specify it by simply adding to the list, as follows:

name: adding_dependencies

dependencies:
json_serializable:
# another packages below

The syntax to specify a dependency is as follows:

<package>: 
<constraints>

Here, you add its name (<package>) followed by the <constraints> fields: version and source. In this case, we did not specify any constraint, so it assumes any available version for the version constraint and default source (pub.dartlang.org).

Note that the colon, :, after the package name is not optional; the dependency list expects every dependency to be a YAML map value. For more information, you can take a look at the YAML documentation at https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.96.146