49

Is there a way to list and update packages that have crossed a major version in pubspec.yaml? (like this method used in NPM)

E.g. when the pubspec.yaml file has this with built_value:

dependencies:
  flutter:
    sdk: flutter
  built_value: ^5.0.0

When built_value is updated to version ^6.2.0 is there a way to upgrade past the major version so the pubspec.yaml is updated to:

dependencies:
  flutter:
    sdk: flutter
  built_value: ^6.2.0

I know I can manually check each package for major versions, but it would be helpful if it was automatic.

S.D.
  • 5,197
  • 9
  • 38
  • 64

8 Answers8

57

With the latest beta versions of Flutter (v1.17) there is now a pub command to check for, and update, outdated dependencies.

To check for outdated dependencies, run:

$ flutter pub outdated -h
Analyze dependencies to find which ones can be upgraded.
This runs the "pub" tool in a Flutter context.

Usage: flutter pub outdated [<arguments...>]
-h, --help    Print this usage information.

Run "flutter help" to see global options.

and this gives output like:

$ flutter pub outdated
Dependencies                           Current              Upgradable           Resolvable           Latest
path                                   *1.6.4               *1.6.4               *1.6.4               1.7.0
permission_handler                     *4.4.0+hotfix.4      *4.4.0+hotfix.4      5.0.0+hotfix.3       5.0.0+hotfix.3

dev_dependencies
analyzer                               *0.36.4              *0.36.4              *0.36.4              0.39.7
build_runner                           *1.7.4               *1.7.4               *1.7.4               1.9.0

transitive dependencies
asn1lib                                *0.5.15              *0.5.15              *0.5.15              0.6.4
permission_handler_platform_interface  *1.0.0               *1.0.0               2.0.0                2.0.0

transitive dev_dependencies
build                                  *1.1.6               *1.1.6               *1.1.6               1.2.2
build_config                           *0.4.1+1             *0.4.1+1             *0.4.1+1             0.4.2
dart_style                             *1.2.9               *1.2.9               *1.2.9               1.3.6

1 upgradable dependency is locked (in pubspec.lock) to an older version.
To update it, use `pub upgrade`.

4  dependencies are constrained to versions that are older than a resolvable version.
To update these dependencies, edit pubspec.yaml.

To update with compatible dependencies, run:

flutter pub upgrade

or to update with potentially breaking changes, use

flutter pub upgrade --major-versions
SoftWyer
  • 1,986
  • 28
  • 33
  • Mentioned in [Dart 3.10 release notes](https://dartcode.org/releases/v3-10/) – SoftWyer May 06 '20 at 07:12
  • 9
    Running `flutter pub outdated` does not update the pubspec file or provide version information for all dependencies if your existing version information is blank. While useful, this does not solve the question asked. – fionbio Sep 23 '20 at 12:36
20

After release of Flutter 2.0 you can follow these flutter command lines to upgrade dependency packages automatically:

  1. flutter pub outdated

  2. flutter pub upgrade --major-versions

RuslanBek
  • 1,592
  • 1
  • 14
  • 30
10

Flutter currently doesn't provide such a feature.
There might be 3rd-party packages that do that. The only one I know is den (https://pub.dartlang.org/packages/den), but this one is not maintained since quite some time and can't be used with recent Dart or Flutter versions.

What might help is to at least get a list of dependencies where newer versions are available.

Upvote https://github.com/flutter/flutter/issues/12627 for that.

In the meantime the workaround mentioned in https://github.com/flutter/flutter/issues/12627#issuecomment-400037072 can be used

Set FLUTTER_ROOT to your Flutter install directory and run pub upgrade. (this requires the Dart SDK to be installed in addition to the Flutter SDK)

$ export FLUTTER_ROOT="/Users/my_user/flutter"

$ pub upgrade
Resolving dependencies... (16.2s)
! analyzer 0.33.0 (overridden) (0.34.2 available)
  args 1.5.1
  async 2.0.8
  boolean_selector 1.0.4
! build 1.1.0 (overridden)
  built_collection 4.1.0
! built_redux 7.5.2 (overridden)
  built_value 6.2.0
  bwu_grinder_tasks 0.2.0-dev.0
  charcode 1.1.2
  cli_util 0.1.3+2
  collection 1.14.11
  contacts_service 0.0.9 (0.1.0 available)
> convert 2.1.1 (was 2.0.2)
  crypto 2.0.6
  csslib 0.14.6
  dart_style 1.2.2
  device_info 0.2.1 (0.3.0 available)
> file 5.0.7 (was 5.0.6)
> firebase_analytics 1.1.0 (was 1.0.6)
...
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
4
  • Upgrade single package

    dart pub upgrade <package_name>
    
  • Upgrade all packages

    dart pub upgrade --major-versions
    
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
1

There a quick and dirty solution that just reads the pubspec.yaml file and then checks the latest version by web-scraping.

https://gist.github.com/spidgorny/ed475cbbe303e1c09c0f6c9f9f57dcad

Example:

cupertino_icons: 0.1.2
location: 2.3.5
flutter_local_notifications: 0.8.4
http: 0.12.0+1
 => 0.12.0+2
haversine: 1.0.2
flutter_map: 0.1.4
 => 0.7.3
map_native: 0.0.11
url_launcher: 5.1.4
flutter_html_view: 0.5.12
flutter_html: 0.8.2
background_fetch: 0.2.0
 => 0.3.2
package_info: 0.4.0+2
 => 0.4.0+6
liquid_pull_to_refresh: 1.1.1
provider: 3.0.0
 => 3.1.0
yaml: any
google_maps_flutter: 0.5.21+7
Slawa
  • 1,141
  • 15
  • 21
1

I was getting a set mock handler error. I tried a flutter clean and flutter pub upgrade but the error continued. I added pigeon: 1.0.7 and with a flutter pub upgrade, no luck.

finally I tried

flutter pub upgrade --major-versions

and it moved forward my flutter dependencies and the code compiled

the command moved my packages versions forward

  flutter_html: ^1.3.0 -> ^2.1.5
  rxdart: ^0.24.1 -> ^0.27.2
  master_detail_scaffold: ^1.1.1+2 -> ^2.0.0
  intl: ^0.16.0 -> ^0.17.0
Golden Lion
  • 3,840
  • 2
  • 26
  • 35
0

enter image description here

You can simply check the version of the dependency even if its version is blank in the pubspec file. Goto Root directory of the project in Android Studio then External Libraries expand it and you can simply view name and version number of the dependency. Don't know about other IDEs.

-1

You can use flutter packages upgrade, Flutter will verify new release versions with constraints notification if there is.

Checkout the documentation about it here: https://flutter.io/docs/development/tools/sdk/upgrading

Warning: (taken from the above link)

Don’t use the pub get or pub upgrade commands to manage dependencies for Flutter apps. Instead, use flutter packages get or flutter packages upgrade. If you want to use pub manually, you can run it directly by setting the FLUTTER_ROOT environment variable.

Pete Houston
  • 14,931
  • 6
  • 47
  • 60
  • "pub get and pub upgrade has been deprecated recently." where did you get that from. That's not true. Also the question is about migrating to newer versions. `flutter packages upgrade does that only within dependency constraints. – Günter Zöchbauer Jan 18 '19 at 06:32
  • @GünterZöchbauer arghhh, sorry about mis-information. Thanks for pointing out. My head is dizzy ...-_- – Pete Houston Jan 18 '19 at 06:51
  • 1
    Now it's correct. They show an error output anyway if used with Flutter. If you set `FLUTTER_ROOT` they can still be used though with the benefit mentioned in my answer. – Günter Zöchbauer Jan 18 '19 at 06:55