> For the complete documentation index, see [llms.txt](https://flutteruniversity.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://flutteruniversity.gitbook.io/docs/learn-flutter/intermediate/package-management.md).

# Package Management

Package management is crucial for managing dependencies and sharing code in a modular and reusable way. In Flutter, package management is facilitated through the use of the `pubspec.yaml` file, where you can specify the dependencies for your project.

## 1. Adding Dependencies 🔗

To add a new package to your Flutter project, you need to specify it in the `pubspec.yaml` file under the `dependencies` section.

```yaml
dependencies:
  flutter:
    sdk: flutter
  http: ^1.1.0
```

Here, we've added the `http` package to our project.

## 2. Updating Dependencies 🔄

To update the packages to their latest versions, you can use the following command:

```bash
flutter pub upgrade
```

## 3. Removing Dependencies 🗑️

To remove a package, simply delete its entry from the `pubspec.yaml` file and run:

```bash
flutter pub get
```

## 4. Creating a Package 📦

You can create your own package for sharing code. Use the following command to create a new package:

```bash
flutter create --template=package my_package
```

## 5. Publishing a Package 🚀

To publish your package to pub.dev, follow the [publishing guidelines](https://dart.dev/tools/pub/publishing) and use the following command:

```bash
flutter pub publish
```

### Assignments 📝

* [ ] Add a new package to your Flutter project.
* [ ] Update the packages in your project.
* [ ] Remove a package from your project.
* [ ] Create a new package and write some reusable code.
* [ ] Publish your package to pub.dev.

This way, you have a simple Flutter app demonstrating how to manage packages and use them in your project.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://flutteruniversity.gitbook.io/docs/learn-flutter/intermediate/package-management.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
