Flutter for Jobseekers

Using 3rd Party Libraries and External Assets

The pubspec.yaml file, adding images and fonts as assets, the Pub package ecosystem, judging package quality, playing audio with a package, and popular packages.

Using 3rd Party Libraries and External Assets

Writing software is hard. That is why, as software developers, we strive to solve a problem only once. Would it not be great if you could benefit from the collected knowledge of Flutter developers everywhere, using their widgets to solve the very problem you are currently facing?

For instance, imagine you develop a practical widget that proves valuable across your entire application. In this scenario, you have successfully addressed a problem once and can now leverage the code repeatedly within your application.

In this chapter, we will look at the package ecosystem for Flutter and Dart, explore some popular packages, and learn how to include things such as images, sounds, fonts, and other resources in your application.

Chapter overview

Structure

  • Introduction to pubspec.yaml
  • Adding images and other assets to your application
  • Introduction to the Pub package management system
  • Finding useful packages on Pub
  • Using a package to play audio
  • Popular Pub packages

Objectives

Upon completion of this chapter, you will have learned how to include custom resources, such as images, fonts, and sounds in your application. You will also have a familiarity with the package management ecosystem for Flutter and Dart and learn how to evaluate the quality and usefulness of packages. You will also learn how to use a package to play an audio file that you have included in your application as a custom resource. Finally, you will learn about popular packages that are often used by the community.

Introduction to pubspec.yaml

Every Flutter application comes with a special file called pubspec.yaml. The file exists at the top-level directory of the project, alongside the lib directory. We often refer to this file as simply "pubspec," which is how we will be referring to it from here on out. Pubspec contains a lot of metadata that Flutter and Dart need to know about your application and is written in the YAML language.

What is important to know about YAML is that whitespace (spaces versus tabs) matters. You can learn more about YAML at https://yaml.org/.

Pubspec is used not only by Flutter but by Dart as well, although many of the sections (called directives) in the file are specific to Flutter.

Used by Flutter and Dart

name, description, publish_to, version, environment (and sdk), dependencies, and dev_dependencies.

Specific to Flutter

Directives that are specific to Flutter are generally either defined within a flutter directive or are named flutter.

Ok, so, with all these directives, what do each of them do, and why would you want to change anything there? Let us run down the list and break it down.

name
directive
The name of your project, but with some specific requirements. This is not the label that will show up under the application icon, but rather the Dart package name. The requirements for the name are that it should be all lowercase with underscores separating the words. It cannot be one of the reserved keywords (as they are described here: https://dart.dev/guides/language/language-tour#keywords=), should not include any non-Latin characters, any accented characters, and may include numbers (although it cannot start with a number).
description
directive
Optional and should be relatively short. (Think the length of a Tweet.) This is mostly useful if you are building a package to share with others, rather than an application. If you are only building an application, you do not technically need to put anything here.
publish_to
directive
Should be set to 'none' if you are working on an application, so that your application isn't accidentally published to Pub (which we will talk about later in this chapter).
version
directive
Where you can increment the version number of your application each time you are ready to release a new version. Flutter is configured, by default, to use this value in the application packages which are created when building the application.
environment → sdk
directive
Used to define the minimum and maximum versions of the Dart programming language which the application can be compiled and run with.
dependencies / dev_dependencies
directive
Where you will add any external packages that your project will use. We will discuss this throughout the rest of the chapter.
flutter
directive
Under the flutter directive, you can add any assets or external files to be included in your application.
Corrected: the Dart keywords list now lives at https://dart.dev/language/keywords. The pubspec reference states the same rules: "The name should be all lowercase, with underscores to separate words, just_like_this. Use only basic Latin letters and Arabic digits: [a-z0-9_]", and the name must not start with digits or be a reserved word (Dart, n.d.-a).

From time to time, Dart introduces new features (such as when constructor tearoffs were introduced in Dart 2.15.) If your application was created before Dart 2.15 was introduced and you wanted to leverage the new constructor tearoff feature in Dart, you would not be able to do so until you updated the minimum version in pubspec.

Likewise, when the next major version of Dart is released, there are bound to be some massive, breaking changes that would require a substantial rewrite of your application. This directive allows you to specify a maximum version, so if Dart is upgraded to a new major version, it does not simply break everything.

Let us explore the flutter directive next with a real-world example: you are building an application based on designs presented to you by a product designer.

Adding images and other assets to your application

The product designer has given you a design that includes some beautiful illustrations to spice up the application you will be building. Now, you need to find a way to include those illustrations in your application. So, what do you do?

It is customary to create an assets folder at the top level of the application where your external assets such as fonts, images, sounds, and anything else you may need to include in your application will live. Many developers choose to further organize their assets folder into several subdirectories, as well.

Images

You take the illustrations your designer has provided to you and save them into a well-organized assets directory.

Simply adding the files, however, does not allow Flutter to access them. We must go back to pubspec and add the directories there, too.

Under the flutter: directive, we will add an assets: directive, followed by any subdirectories. Here is what that might look like, although it will differ based upon what directories you've created:

pubspec.yaml
flutter:
  assets:
    - images/
    # If there are any subdirectories you'd like to include,
    # be sure to add those to the list as well.
    - images/another_subdirectory/
    - fonts/
    - sounds/
Note that it is not necessary to specify each file explicitly. By specifying a directory where multiple files exist, Flutter is smart enough to know to include everything within the directory.

Finally, we are ready to add the image to our application! The Image widget has an easy way to display images that you have included in your application as assets. It can be accessed using the Image.asset() constructor, then passing in the path to the image as a positional parameter:

Image.asset('assets/images/my_beautiful_picture.jpg'),
Corrected: "Each asset is identified by an explicit path (relative to the pubspec.yaml file) where the asset file is located" (Flutter, n.d.). With the files in an assets folder, the entries must include it (- assets/images/, - assets/images/another_subdirectory/, and so on); as printed, images/ does not match assets/images/my_beautiful_picture.jpg. A directory entry also includes "only files located directly in the directory", which is why each subdirectory needs its own entry.

That is all there is to it! Now you can add all those beautiful illustrations that the designer gave you. A job well done!

Fonts

Adding fonts can be done in a similar way, although there are a couple of extra options available to us.

Name the family

First, we specify the name of the font we will be using. This name is how we will refer to the font within the application and does not necessarily have to be the name of the font itself.

List the font files

Next, we specify each font file as an asset for the font family. We do this because some fonts are split into multiple files, where each file may define the font with a different font weight, or how thick the letters are.

A complete example with multiple font files of different font weights and styles might look something like the following:

pubspec.yaml
flutter:
  fonts:
    - family: Comic Sans
      fonts:
        - asset: assets/ComicSans-Regular.ttf
        - asset: assets/ComicSans-Bold.ttf
          weight: 700
        - asset: assets/ComicSans-Italic.ttf
          style: italic

However, if your font only has one file, it is possible to specify a single asset with no associated font weight or style:

pubspec.yaml
flutter:
  fonts:
    - family: Comic Sans
      fonts:
        - asset: assets/ComicSans.ttf

Now that you have got your font set up in pubspec, you can reference it by the name you have given it in your application:

Text(
  'Comic Sans is arguably the greatest font face of all time.',
  style: TextStyle(
    fontFamily: 'Comic Sans'
  ),
),

Sounds

When it comes to playing audio, things become a bit trickier. Since Flutter has no native way of playing audio, we will have to employ the use of a package.

Let us first explore Flutter's package management system, and then we can look at a couple of useful packages, including one which will allow us to build a fully featured audio-playing application.

Introduction to the Pub package management system

From the very start, Flutter was designed to allow the ability to import other people's code and use it in your own project. This ability to reuse code written by others opens the door to building apps and experiences that would not otherwise be possible for a sole developer to accomplish on their own.

There are thousands of packages — all open-source — that have been created by and shared with the Flutter community, for free. Developers who create a package and share it with the community submit their package to a website called Pub (https://pub.dev/), where anyone can go to discover and see the documentation for all manner of packages shared by and to the community.

Adding a dependency

Packages are added to your Flutter project by modifying pubspec in the dependencies: directive. The way you add a package is by specifying first the package name, followed by a colon, then the version number. A complete example would look like the following:

pubspec.yaml
dependencies:
  flutter:
    sdk: flutter
  google_fonts: ^5.0.0
  path: any
  provider: 6.0.5

Note that flutter is always included as a dependency for our Flutter projects. In this example, we have added the google_fonts package to our application, allowing us to use any of the fonts listed at https://fonts.google.com/ in our application. Also, note the caret (^) in front of the version number. We use this to specify a version range, rather than a specific version. We also added the path and provider packages, with path being set to the version any and provider being set to the version 6.0.5.

Version ranges

Much like an application, a package can have its own dependencies. These dependencies will also have version numbers specified in their pubspec. When adding a package with its own dependencies as a dependency to your application, the package's dependencies are also added to your application as transitive dependencies.

If a package requires a particular version of a dependency, for example, version 2.4.1, and you have the same dependency in your application, but you have set the version to 2.4.0, there would be a version mismatch. Your application would require an older version, whereas the package would require a newer version.

This is where version ranges come into play. By specifying a caret before the version, Flutter knows that it's allowed to use a range of acceptable versions. In our example, specifying ^5.0.0 would allow any version from 5.0.0 to 6.0.0, satisfying the needs of both the application's dependency as well as the package's dependency. It is for this reason that it is recommended to use version ranges when adding dependencies to your application.

Corrected: the caret range stops before the next major version, so ^5.0.0 means >=5.0.0 <6.0.0: "^version means the range of all versions guaranteed to be backwards compatible with the given version", up to the next one to introduce a breaking change (Dart, n.d.-b). Version 6.0.0 itself is not allowed.

Specific version (provider: 6.0.5)

It is also possible to use a specific version, such as when we specified a version for provider. In our example, only version 6.0.5 is allowed to be resolved, requiring other packages to conform to that decision. This is the most restrictive way to specify a version number.

Range (google_fonts: ^5.0.0)

A range of acceptable versions, satisfying both the application and its packages. The recommended way.

Any (path: any)

The version of path we chose, any, is the least restrictive. If you specify any for the version, the latest possible version that works with the rest of your dependencies will be used.
Using any can cause breaking changes if the package suddenly updates to a new, major version, so be careful when using this.

Downloading and importing

Once the dependency has been added to your pubspec, it will need to be downloaded and cached before you can start using it. Be sure to save the file, then use the command flutter pub get to download the package.

flutter pub get

Now that the package has been downloaded, it is ready for use in your project. The last step to using the package in your project is to import it into the file where you want to use it. Let us import the google_fonts package that we added as a dependency earlier. At the top of the file, you will include it like the following:

import 'package:google_fonts/google_fonts.dart';

From there, you will be able to use the widget(s) provided by the package as though they were code you have written in the file, yourself. You are already used to doing this: we have been using the Material and Cupertino packages throughout this book!

Keeping packages up to date

Packages are updated all the time by their developers to meet their own needs and the needs of the community. It is a good idea to keep your packages up to date with the newest versions, but doing that by hand can be a long, frustrating process. Thankfully, we have another command for that.

To upgrade the packages in your project to the latest versions within the version ranges you specified in your pubspec, you can run the command flutter pub upgrade. If you would like to include newer versions of packages that are not within your specified version ranges as well, you can instead use the command flutter pub upgrade --major-versions.

flutter pub upgrade
flutter pub upgrade --major-versions

Troubleshooting the package cache

Finally, there may come a time when you find yourself needing to troubleshoot why your application is not building and you suspect it might have something to do with the packages you have imported.

flutter pub cache clean

Removes all packages which have been downloaded (this is generally followed by flutter pub get to re-download the packages necessary for your project).

flutter pub cache repair

Re-downloads all the packages for your project without cleaning the cache first.
Keep in mind that running these commands will affect the packages for all projects, not just the one you are currently working on.

Finding useful packages on Pub

Pub has a huge selection of packages to choose from. Some packages are written for Dart (which can then be used in any Dart-based application, including Flutter applications), whereas others explicitly require the Flutter framework. Furthermore, packages are sometimes designed to work with specific platforms and may or may not have support for others. There may be a package that works on Android and iOS but isn't compatible with the Web or desktop operating systems, for example. With so many packages available, though, how do you decide which are worth using and which are better to pass on?

1. The problem

Choosing the right package starts with knowing what problem you are trying to solve.

2. The platforms

Determining the platform(s) you will be targeting with your application.

3. The quality

Arguably the most important consideration: likes, popularity, and Pub Points.

The problem

In fact, there is very little (if anything) that you cannot accomplish on your own by using a package from Pub. However, the aim is to save development time and rely on the experience of others to provide value.

Not all packages on Pub provide widgets that will be drawn to the screen. In fact, many packages on Pub offer features that are more abstract, such as widgets that help with state management, interface with databases and other services, or make sharing content to other applications easier. Also, many, many other things that would just be time-consuming to write from scratch every time you need to do something that the Flutter framework does not immediately provide to you.

It is important to pick a package that is suitable for the problem you are trying to solve, so ensure that you take the time to consider this carefully.

The platforms

As previously mentioned, many packages are only available for some of the available platforms that Flutter is capable of building for. Furthermore, some packages implement features that might not make sense for all platforms.

If you are building an application that targets the Web, it does not make sense to use a package that implements the ability to report app crashes to Google's Firebase Crashlytics. (In fact, the package available on Pub to do this, firebase_crashlytics, doesn't have support for web, at all, nor does it have support for Windows, at least as of the time of writing.)

The quality

Finally, and arguably the most important consideration, is the quality of the package. There are three broad metrics by which you can judge the quality of a package: likes, popularity, and Pub Points.

Likes

A simple enumeration of how many developers have logged into Pub and pressed the thumbs-up button next to a package. Were you to do the same, you could find your list of liked packages under the My pub.dev menu at the top of the page, then by navigating to likes.

Popularity

Currently, this is a measure of the number of apps that depend on the given packages over the past 60 days, measured by download count (and adjusted for automatic downloads, such as with build tools), and displayed as a percent from 0% (the least used package) to 100% (the most used package.) This metric's calculation is bound to change once the team has completed work on measuring absolute usage counts, however that is not currently the case as of the time of writing.

Pub Points

Alongside the popularity metric, this is arguably the most useful metric. Unlike the other metrics, this value is automatically calculated and cannot be directly influenced by the number of people liking or using the package.
Corrected: the popularity percentage has since been replaced. pub.dev now scores packages on "Likes", "Pub Points", and "Download count", the last being "A measure of how often a package is downloaded, providing insight into what other developers are using" that "should only be regarded as an indicator of popularity" (pub.dev, n.d.-a).

There are many checks which are done automatically on a package to determine its Pub Points by a tool called pana. Pana automatically evaluates the quality of the package by looking at a multitude of criteria within several categories, then scoring each category independently before producing a total number (which, at the time of writing, is out of 140 possible points). The criteria for how these points are awarded, at least at the time of writing, are as follows:

Follow Dart file conventions
30 points total
  • Provide a valid pubspec.yaml (10 points)
  • Provide a valid README.md (5 points)
  • Provide a valid CHANGELOG.md (5 points)
  • Use an OSI-approved license (10 points)
Provide documentation
20 points
  • Provide an example usage of the package (10 points)
  • 20% or more of the public API has dartdoc comments (10 points)
Provide support for all 6 platforms
20 points
Pass static analysis
30 points
Code has no errors, warnings, lints, or formatting issues.
Support up-to-date dependencies
20 points
Dart 3 and Flutter 3.10 compatibility
20 points
Corrected: pub.dev's scoring help no longer publishes a total or a point value per check. It says "Pub points are awarded in six categories", lists the checks under Follow Dart file conventions, Provide documentation, Platform support (including Support modern toolchains such as Swift Package Manager and Wasm), Pass static analysis, and Support up-to-date dependencies (the latest stable Dart SDK, Flutter SDK and dependencies), and has no separate Dart 3 / Flutter 3.10 check (pub.dev, n.d.-a).
Given the rigorous criteria by which Pub Points are calculated, it should come as no surprise that Pub Points are one of the easiest ways to determine the overall quality of any given package.
Finally, it is always an excellent idea to read the package description thoroughly. There have certainly been times when a package was developed to overcome a shortcoming in Dart or Flutter, then later that shortcoming was remedied, making the package obsolete. An excellent example of this is the supercharged package.

Using a package to play audio

Now that we have a firm grasp of what a package is, where to find them, and how to evaluate them for quality before depending on them in our application, let us loop back to the earlier example of finding and using a package to play audio.

As we discussed earlier, Flutter does not (natively) support playing audio, so using a package is the easiest way to add this functionality. Any package we use will have platform-specific code for each supported platform which does the heavy lifting of playing audio. There will also be a widget (or perhaps several) which will enable us to choose what audio to play and control the playback.

Searching Pub for audio

By searching for audio on https://pub.dev/, we are presented with several options.

One thing to note is that these results are certainly outdated from the time of writing to the time you are reading this. Many of these packages may have been updated in the intervening time. Your results are almost certain to be different than those listed here.

Generally speaking you will probably notice the packages audio, dart:web_audio, dart:html, material, flutter_sound, flutter_widget_from_html, and just_audio, which is what we will be focusing on for our example. Let us start by looking at the audio package (figure 6.1):

Figure 6.1: The pub.dev search result listing for the audio package.

This package has very few likes, a very low number of Pub Points, and relatively weak popularity. Also note the last update was version 0.0.5, which was released four years prior. In addition, Pub cannot determine which platforms this package will run on. Finally, there's no Dart 3 compatibility. Given all these elements together, it's a safe bet that this package is not a good choice for our application.

Let us look at the next set of results; refer to figure 6.2:

Figure 6.2: More search results for the query "audio" on pub.dev.

Core libraries

The top three are core libraries, meaning that they are built-in to the Flutter framework or Dart itself. Since we know that Flutter (and Dart) are incapable of playing audio, we can safely ignore them.

flutter_sound

This package has a huge number of likes, a maximum number of Pub Points, and an excellent popularity rating. Additionally, it supports the Web and mobile platforms and works with Dart 3. This would be an excellent choice, so let us add it to our list of potential solutions and keep looking.

flutter_widget_from_html

Sounds like it will render HTML code as Flutter widgets, which does not match what we are looking for. Despite the rest of the stats looking good, it will not solve our problem.

There are several more search results on the page, and several pages of search results in total. However, the very next search result looks promising (figure 6.3):

Figure 6.3: The pub.dev search result listing for the just_audio package.

The just_audio package, like the flutter_sound package, has the maximum number of Pub Points, was updated within the past couple of days, supports Dart 3, and has an incredibly popular rating. Where it sets itself apart is the enormous number of likes and the Flutter Favorite badge. Good thing we did not stop looking when we found flutter_sound, because just_audio looks like it is an even better choice!

The package page

Now that we have found the package we want to use, let us explore it a bit further. To start, let us look at the package page (as shown in figure 6.4). You can find this on your own by navigating to https://pub.dev/packages/just_audio.

Here, we can find a slew of useful information about the package. At the top, we see the package name and current version. (There is even a handy copy icon next to the version, which will copy the line we need to paste into our pubspec!). It tells us the last time the version was updated, the developer, and all the useful bits about Dart 3 support, being a Flutter Favorite, the supported platforms, and so on:

Figure 6.4: The package details page for the just_audio package on pub.dev.

The tabbed view below defaults to the package's readme, which has even more useful information:

Readme
tab
If you scroll down, you will even see some examples detailing exactly how to use it in the application.
Changelog
tab
Details all the changes made in each version that has been released.
Example
tab
Has a complete working example that you could copy/paste into your application.
Installing
tab
Tells you how to add it as a dependency in your code.
Versions
tab
A useful way to download a copy of any given version (or see the documentation for said version).
Scores
tab
Breaks down the Pub Points calculation to see exactly what points were awarded for.

Other useful information on this page can be found on the right sidebar, where you can see links to the homepage, GitHub repository (in case you would like to browse the source code), and a place to see/report any issues with the package. There is also a complete API reference, which covers the entirety of the package and how to use every aspect of it (although, in the case of just_audio, the relevant information is on the readme tab, so the API reference simply displays this information.)

Try it yourself

Normally, this is where we would go step-by-step over how to add this package to your application and start using it. This time, however, why not try following the instructions on the installing tab, then use the example to get it up and running on your own? After all, this is often the process you will need to follow when you are out there building apps. (Plus, you have got this!) Do not forget to run flutter pub get once you have added the dependency!

There is no shortage of packages on Pub. Sometimes the most difficult part of choosing a package is even knowing what is even available and what other people are using to solve problems. If you have already visited pub.dev, you will no doubt have noticed the most popular packages and top Flutter packages sections on the home screen (figure 6.5). (There is also a top Dart packages section if you are looking for something specific to Dart.)

This is an excellent place to start browsing packages that other developers are commonly using. Sometimes inspiration for a new application or feature can come from just browsing these lists. You might even discover a solution to a problem you did not know you were having!

Figure 6.5: Popular packages on pub.dev.

Let us look at a couple of the most popular packages to understand what problems other developers are trying to solve.

shared_preferences

Have you ever thought it might be useful to store some user data on the device? Maybe you are storing the user's preference for a light/dark mode. Perhaps you want to keep track of how many times they have opened the application. Maybe you want to store user-generated content (such as a list of items) so that it is available next time the app is launched. If you have answered yes to any of these questions, look no further than shared_preferences!

With shared_preferences, you can store integers, Booleans, doubles, strings, and lists of strings to a user's device with ease. Then, you can easily recall those values later. It works on all platforms that Flutter can target.

Beware that the data is stored locally on the device — if you build an application that uses shared_preferences, do not expect the same data to be available on multiple devices that the user uses.

url_launcher

If you want to have a tappable email address which automatically launches the user's email client and pre-fills the to, subject, and body lines, look no further than url_launcher! Why stop at emails, though?

Email

Launch the email client with the to, subject, and body lines pre-filled.

Website

You could launch a website.

Phone

Automatically enter a phone number into the user's default phone application so all they need to do is press call.

SMS

Initiate an SMS conversation.

File

Or even open a file.

All of this is possible on every platform that Flutter targets.

dio

The default HTTP client that comes with Dart is usually good enough for most tasks. However, there are times when you need to do something that the built-in client just cannot handle. This is where dio comes to the rescue!

Global settings

Use dio to configure global settings for all HTTP connections made within your application, such as setting an authorization header.

Interceptors

Want access to better debug logging to see what requests and responses are being made more easily? Try using an interceptor! (Write your own or find a package that does it for you!)

If for whatever reason you find that Dart's HTTP client is not quite doing the trick, look at Dio. You will be glad you did.

flutter_bloc

Stateful widgets can only get you so far in life. The minute a stateful widget is disposed of the state is lost. That might be fine for some use cases, but other times you might need to save that state. You could be building a list/details application. When viewing the details, you have got the option to update the title. Save the changes by passing the updated details to a BLoC, and the list will rebuild automatically.

A lot of business logic can be moved outside the widget's build method by using a BLoC, as well. By leveraging the event-driven nature of the BLoC, you can send an event to the BLoC (sometimes with parameters), allow the BLoC to do the heavy lifting, and then the BLoC will return a given state. That state can be used to build your widget in a different way. For example:

Send an event

Sending an event of load all the things to the bloc would trigger the BLoC to reach out to an API and acquire some data.

Process the data

Then, the data would be processed.

Return a state

If successful, a state of all good! could be sent back; otherwise a state of that did not quite work out could be sent instead.

Build the widget

When the widget is built, it could check for the success/failure states and either return the details of the response or an error message.

And we are only scratching the surface of what flutter_bloc can do! In fact, we are going to discuss it in-depth in Chapter 9: State Management and the BLoC.

isar

If you have found yourself using shared_preferences and realizing the limitations of what you are able to store and how you can retrieve it, you need isar. This package is an easy-to-use NoSQL database for storing and retrieving any type of data imaginable. It is easy to use, fast, and has excellent documentation. The limitations of shared_preferences are a thing of the past with isar!

Corrected: check isar's maintenance before depending on it. When this page was written (November 2026), its latest stable version on pub.dev, 3.1.0+1, had been published three years earlier, with only 4.0.0-dev prereleases after it (pub.dev, n.d.-b).

Package of the Week

This is just a small sampling of some of the more popular packages which can be found on Pub.

The Flutter team has a Package of the Week playlist on YouTube (see the Further reading section at the end of the chapter) in which they choose a package from Pub each week and give a brief overview of the problem that the package seeks to solve, then show an example of it in action. They are short videos, and you are highly encouraged to check out the playlist!

Conclusion

We have covered a lot of ground in this chapter. By now, you know what pubspec.yaml is and how to use it to add packages and resources to your application. You learned how to find and evaluate the quality of packages using Pub, the package manager for Flutter and Dart, and pub.dev, the website where all the available packages can be found. Then, we learned how to make our application play sounds. Finally, we explored a small selection of some popular packages that many developers come back to time and time again.

How are you feeling about all this new information? If you are overwhelmed, that is perfectly okay. Take a break, stretch, drink some water, and come back to it when you are ready. Or are you feeling confident that you are really starting to get a good grasp on Flutter? That is great!

We have almost all the tools we need to start building our first application. There are just a couple more concepts we need to learn before we can start digging into building something from scratch. Next up, we are going to explore the concept of asynchronous operations and use them to communicate with an API. So, whenever you are ready, let's async await some new concepts!

Questions

  1. What is pubspec.yaml used for?
  2. What language is pubspec.yaml written in?
  3. What are the required directives for Flutter in pubspec.yaml, and what do they do?
  4. How do you update the package versions in pubspec.yaml with a single command?
  5. How do you add images, fonts, sounds, or other assets to your application?
  6. What is Pub?
  7. How does dependency version pinning work?
  8. Where can one browse a list of packages that are available to add to a Flutter or Dart project?
  9. What are Pub Points and how are they calculated?
  10. How can one save a list of their favorite packages on Pub?
  11. How can you play audio in your Flutter application?
  12. Where can you find a list of popular Flutter and Dart packages?
  13. What are some ways in which data can be persisted across app launches?
  14. What YouTube playlist does the Flutter team use to showcase popular packages?

Key terms

Asset
Any file which is included with a project, such as an image or font.
Pana
The tool used to automatically calculate the number of Pub Points a given package has earned.
Pub
The package ecosystem for Flutter and Dart.
pubspec.yaml
The configuration file for a Flutter or Dart project which includes useful items such as the package name and description, the version of Dart used by the project, and any dependencies the project may have.
Pub points
A number generated by pana, which is used to loosely determine the quality of a given package.

Command reference

flutter pub cache clean
Removes all cached packages, globally.
flutter pub cache repair
Re-downloads all cached packages, globally.
flutter pub get
Downloads all of the packages specified in the pubspec.yaml file and caches them locally for use in your application.
flutter pub outdated (--major-versions)
Lists out-of-date dependencies.
flutter pub upgrade
Updates pubspec.yaml with the newest available versions of packages within their allowed version ranges.
flutter pub upgrade --major-versions
Updates pubspec.yaml with the newest available versions of packages, even if those new versions have a version available outside of the allowed version ranges.
Corrected: plain flutter pub upgrade resolves the newest allowed versions and writes them to the lockfile ("it writes a lockfile to ensure that dart pub get will use the same versions"); it leaves the constraints in pubspec.yaml as they are. Only --major-versions "Also updates pubspec.yaml with the new constraints" (Dart, n.d.-c). The pub outdated reference lists no --major-versions option; its options are --[no-]dependency-overrides, --[no-]dev-dependencies, --json, --[no-]prereleases, --[no-]transitive and --[no-]up-to-date (Dart, n.d.-d).

Further reading

Flutter Package of the Week

Check out the Flutter team's Flutter Package of the Week playlist on YouTube.

Package versioning

Learn more about package versioning.

Pub Points

Learn more about how Pub Points are calculated.

References

Copyright © 2026