Dart版本为2.2.0,但出现错误,要求版本> = 2.2.0

时间:2019-03-19 18:07:44

标签: dart flutter

我拥有最新版本的Flutter,并且我正在尝试运行官方的Flutter Gallery应用。当我做dart --version时,我得到

Dart VM version: 2.2.0 (Tue Feb 26 15:04:32 2019 +0100) on "macos_x64"

但是,当我尝试获取软件包时:

[flutter_gallery] flutter packages get
Running "flutter packages get" in flutter_gallery...            
The current Dart SDK version is 2.1.2-dev.0.0.flutter-0a7dcf17eb.

Because flutter_gallery requires SDK version >=2.2.0 <3.0.0, version solving failed.
pub get failed (1)
exit code 1

有趣的是,当我运行flutter upgrade时,它列出了较旧版本的Dart(工具)。

Upgrading Flutter from /Users/leejohnson/dev/flutter...
From https://github.com/flutter/flutter
   a1bee54fd..59ce7d6bf  dev        -> origin/dev
   55a2ee588..f8f2b043e  master     -> origin/master
 * [new tag]             v1.3.13    -> v1.3.13
Already up to date.

Upgrading engine...
Already up-to-date.

Flutter 1.2.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8661d8aecd (5 weeks ago) • 2019-02-14 19:19:53 -0800
Engine • revision 3757390fa4
Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

如果我正确理解此错误,则Flutter没有使用最新版本的Dart,但Flutter官方示例应用程序需要它。我该如何解决?

3 个答案:

答案 0 :(得分:7)

dart --version的输出与Flutter完全无关。您需要检查的是flutter doctor -vflutter --version。您的情况显示为Tools • Dart 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

您可能需要切换到另一个频道,直到下一个稳定的频道更新

flutter channel dev

flutter channel master

答案 1 :(得分:2)

Flutter在flutter/bin/cache/中有自己的dart-sdk。因此,当您执行dart --version时,它可能是系统中的另一个dart sdk。

enter image description here

答案 2 :(得分:0)

对于陷入困境的其他人(其他渠道已中断),我发现正在切换到稳定版,然后在稳定版中切换版本对我来说是固定的。您可以执行以下操作:

flutter versions

flutter versions 1.5.5(或其他版本)