升级你的 Flutter 版本

无论你使用哪个 Flutter 发布渠道 ,你都可以使用 flutter 命令来更新 Flutter SDK 和 app 所依赖的 packages。

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

为了让 flutter 命令正确工作,你工程下的 pubspec.yaml 文件必须要求使用 Flutter SDK。

For the flutter command to work correctly, your app’s pubspec.yaml file must require the Flutter SDK.

例如,下面的代码段指定了 flutterflutter_test packages 依赖 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

升级 Flutter SDK 和 packages

Upgrading the Flutter SDK and packages

为了升级你 app 依赖的 Flutter SDK 和 packages,在 app 根目录执行 flutter upgrade 命令(与包含 pubspec.yaml 文件的目录相同):

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

这个命令首先获取你的 Flutter 渠道可用的最新的 Flutter SDK 版本。接着这个命令更新你 app 依赖的每一个 package,到最新的兼容版本。

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.

如果你想使用一个更加新的 Flutter SDK 版本,切换到不太稳定的 Flutter 渠道,并且运行 flutter upgrade

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

切换 Flutter 发布渠道

Switching Flutter channels

Flutter 有 4个发布渠道stable, beta, dev, 和 master。我们推荐使用 stable 渠道除非你需要更加新的版本。

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

要切换到其它渠道,使用 flutter channel <channel-name>。当你切换了渠道以后,使用 flutter upgrade 下载 Flutter SDK 和依赖的 packages。例如:

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

仅更新 packages

Upgrading packages only

如果你已经修改了 pubspec.yaml 文件,或者你想仅仅更新你 app 依赖的 packages (而不是同时更新 packages 和 Flutter SDK)就使用 flutter pub 命令之一。

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 pub commands.

为了获取 pubspec.yaml 文件里列出的所有依赖,但排除不必要的更新,使用 get 命令:

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

$ flutter pub get

为了更新 pubspec.yaml 文件里列出的所有依赖到 最新的兼容版本 ,使用 upgrade 命令

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

$ flutter pub upgrade

获得最新通知

Keeping informed

我们会将最新的 breaking change (重大改动) 通知到 Flutter 通知邮件群组,与此同时,你可以在 Flutter 开发者邮件群组里向大家提问等。我们希望得到你的反馈!

We publish breaking change announcements to the Flutter announcements mailing list. You can also ask questions on the Flutter dev mailing list. Aside from subscribing to receive announcements, we’d love to hear from you!