Flutter and the pubspec file

Flutter and the pubspec file

Table of contents

Every Flutter project includes a pubspec.yaml file, often referred to as the pubspec.

A basic pubspec is generated when you create a new Flutter project. It's located at the top of the project tree and contains metadata about the project that the Dart and Flutter tooling needs to know.

The pubspec is written in YAML, which is human readable, but be aware that white space (tabs v spaces) matters.

( Note

The first time you build your project, it creates a pubspec.lock file that contains specific versions of the included packages. This ensures that you get the same version the next time the project is built.)

When you create a new project with the flutter create command (or by using the equivalent button in your IDE), it creates a pubspec for a basic Flutter app.


Common types of assets include static data (for example, JSON files), configuration files, icons, and images (JPEG, WebP, GIF, animated WebP/GIF, PNG, BMP, and WBMP).

Besides listing the images that are included in the app package, an image asset can also refer to one or more resolution-specific "variants". For more information, see the resolution aware section of the Assets and images page. For information on adding assets from package dependencies, see the asset images in package dependencies section in the same page.


As shown in the above example, each entry in the fonts section should have a family key with the font family name, and a fonts key with a list specifying the asset and other descriptors for the font.

For examples of using fonts see the Use a custom font and Export fonts from a package recipes in the Flutter cookbook.