17
votes

My Flutter project has a dependency flutter_dotenv at version ^2.0.1 and I want to automatically upgrade to the new version ^2.0.2.

I am running the following command to upgrade it:

flutter pub upgrade

Reference: Upgrading packages only

To update to the latest compatible versions of all the dependencies listed in the pubspec.yaml file, use the upgrade command:

flutter pub upgrade

However nothing seems to happen. pubspec.yaml does not change, and the console output does not mention of a new version (which would be enough).

My pubspec.yaml looks like this:

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_dotenv: ^2.0.1
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true
5

5 Answers

15
votes

Flutter automatically upgrades non-breaking changes based on semantic versioning. You wouldn't want breaking changes to be automatic. The updates are reflected in pubspec.lock, but not pubspec.yaml.

There are a couple IDE plugins that can help you to upgrade packages more easily than looking them up one by one on pub.dev.

Android Studio

Flutter Pub Version Checker

This plugin highlights any dependencies in pubspec.yaml you have that are out of date so that you can choose to update them if you want to.

Visual Studio Code

Pubspec Assist

This plugin makes it super simple to add or update a dependency without going to pub.dev, but you still have to check them one at a time.

20
votes

Above method works but you can use this command:

flutter pub upgrade --major-versions

It will update all your dependencies.

Also check "How to correctly add dependencies to avoid "Version solving failed" error

Refer to this: https://stackoverflow.com/a/67517680/13500457

I hope it clears everything, happy coding!

7
votes

Running pub won't ever change pubspec.yaml. However, it might solve to a version different from the 'base' version specified - the leading caret allows pub to solve to:

the range of all versions guaranteed to be backwards compatible with the specified version

Check in the pubspec.lock file and you'll probaby see that pub has already solved to version: "2.0.2"

2
votes

There are two ways of declaring dependency versions:

  1. Caret syntax - It guarantees backwards compatibility. Example: ^1.3.0
  2. Traditional syntax - Great flexibility, many options for your control. Example: >=1.2.3

The behavior is similar to package.json with Node.js dependency management.

Your chosen way of declaring dependencies in the pubspec.yaml will define how the actual dependencies will be defined in the pubspec.lock file.

0
votes

I think the best command for me is below. It resolves the version conflict also.

dart pub upgrade --null-safety