当前位置: 首页 > 文档资料 > Flutter 英文文档 >

Upgrading Flutter

优质
小牛编辑
141浏览
2023-12-01

No matter which Flutter release channel you follow, you can use the flutter command to upgrade your Flutter SDK and the packages that your app depends on.

One-time setup

For the flutter command to work correctly, your app’s pubspec.yaml file must require the Flutter SDK. For example, the following snippet specifies that the flutter and flutter_test packages require the Flutter SDK:

name: hello_world
dependencies:
  flutter:
    sdk: flutter
dev_dependencies:
  flutter_test:
    sdk: flutter

Upgrading the Flutter SDK and packages

To update both the Flutter SDK and the packages that your app depends on, use the flutter upgrade command from the root of your app (the same directory that contains the pubspec.yaml file):

$ flutter upgrade

This command first gets the most recent version of the Flutter SDK that’s available on your Flutter channel. Then this command updates each package that your app depends on to the most recent compatible version.

If you want an even more recent version of the Flutter SDK, switch to a less stable Flutter channel and then run flutter upgrade.

Switching Flutter channels

Flutter has four release channels: stable, beta, dev, and master. We recommend using the stable channel unless you need a more recent release.

To view your current channel, use the following command:

$ flutter channel

To change to another channel, use flutter channel <channel-name>. Once you’ve changed your channel, use flutter upgrade to download the Flutter SDK and dependent packages. For example:

$ flutter channel dev
$ flutter upgrade

Upgrading packages only

If you’ve modified your pubspec.yaml file or you want to update only the packages that your app depends upon (instead of both the packages and Flutter itself), then use one of the flutter packages commands.

To get all the dependencies listed in the pubspec.yaml file, without unnecessary updates, use the get command:

$ flutter packages get

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

$ flutter packages upgrade

Keeping informed

We publish breaking change announcements to our mailing list. We strongly recommend that you subscribe to get announcements from us. Plus, we’d love to hear from you!