The Flutter pubspec.yaml In Detail

Flutter category image

The pubspec.yaml file is the main configuration file for your Flutter app. In this article, we’ll have a look at its contents.

When developing a Flutter app or package, you’ll eventually come across the pubspec.yaml file. I’ll give you an overview of the contents and how to work with the file. It contains package dependency information, SDK version constraints, or project settings like the name. The used syntax is YAML, an easy-to-use and understandable format. Pay attention to indentation, colons, and link breaks. Otherwise, there will be parsing errors by the Flutter/Dart tooling.

Get Free Daily Flutter Content!

Small daily Flutter portions delivered right in your inbox. A title, an abstract, a link, and you decide if you want to dive in!

The default file

When creating a new Flutter project, a pubspec.yaml file is automatically created depending on the project template. The app template’s file that will be created if you don’t specify another template looks like this (comments were removed):

name
The name of the app. Allowed characters are lower-case letters, numbers, and underscores.

description
A short description of your app.

publish_to
Always none for apps.

version
Your app version with semantic versioning syntax.

environment
Dart SDK version constraints. Always specify lower and upper bound.

dependencies
List of all packages that your app needs to work

▶▶ flutter
Section is required for every Flutter project

▶▶▶ sdk
Section is required for every Flutter project. Value must be flutter

▶▶ cupertino_icons
Required when using iOS style icons

dev_dependencies
List of all packages that your app needs during development to work (for example packages for unit testing)

▶▶ flutter_test
Section is required for every Flutter project that includes tests

▶▶▶ sdk
Section is required for every Flutter project that includes tests. Value must be flutter

flutter
All Flutter related settings can be found in this section

▶▶ uses-material-design
Required if you use the Material icon font

▶▶ assets
Any file you want to include in your app (like TXT, JSON, PNG, BMP) comes here. Either specify the correct relative path to a file (- images/a_dot_burr.jpeg) or use a folder path with a wildcard to include all files of that folder (- images/). For more information about assets have a look at the following link:

▶▶ fonts Required if your app uses custom fonts. The following link provides additional details:

Notes

? The file must be located in the project root folder
? The file name must not be changed
? If the YAML syntax is messed up, the Dart/Flutter tooling will indicate where the error is
? On the first build, a pubspec.lock file will be generated from the pubspec.yaml file

💡 Tip

If you want to develop a package and publish it to the Dart package repository, additional fields will be required. Have a look at the following links for more details.

Conclusion

This brief summary should give you an idea of what the pubspec.yaml file is all about. If you need more information, check the Flutter docs.

Related articles