[英]Flutter says Dart version is 2.13.4 even though it's 2.16.0
I'm trying to install this http package to my flutter app.我正在尝试将此http package安装到我的 flutter 应用程序中。
But when i perform flutter pub get
I get this error:但是当我执行
flutter pub get
我得到这个错误:
The current Dart SDK version is 2.13.4.
Because http 0.13.4 requires SDK version >=2.14.0 <3.0.0 and no versions of http match >0.13.4 <0.14.0, http ^0.13.4 is forbidden.
So, because app depends on http ^0.13.4, version solving failed.
pub get failed (1; So, because spotlight depends on http ^0.13.4, version solving failed.)
However I performed flutter upgrade
before this and it says i'm on the latest version which includes Dart.但是我在此之前执行了
flutter upgrade
,它说我使用的是最新版本,其中包括 Dart。
Flutter is already up to date on channel master
Flutter 2.9.0-1.0.pre.198 • channel master • https://github.com/flutter/flutter.git
Framework • revision 3f775d864e (11 hours ago) • 2021-12-26 08:59:07 -0500
Engine • revision d56b72b117
Tools • Dart 2.16.0 (build 2.16.0-135.0.dev) • DevTools 2.9.2
Why is this?为什么是这样?
Edit: pubspec.yaml
below:编辑:
pubspec.yaml
下面:
name: app
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
http: ^0.13.4
dev_dependencies:
flutter_test:
sdk: flutter
In my settings it says 2.13.4
:在我的设置中它说
2.13.4
:
EDIT: So the problem is the Flutter path is incorrect when I type which flutter
.编辑:所以问题是当我键入
which flutter
时 Flutter 路径不正确。 It is different from my path in Android Studio.和我在Android Studio的路径不一样。 How can I change this?
我怎样才能改变这个?
Look for the sdk setting in your project's pubspec.yaml
file.在项目的
pubspec.yaml
文件中查找 sdk 设置。 This is what determines the minimum Dart SDK version for you project.这决定了您项目的最低 Dart SDK 版本。 Change to lower bound to 2.14.0.
将下限更改为 2.14.0。
environment:
sdk: ">=2.14.0 <3.0.0"
If you are using FVM, make sure you point the Flutter SDK path to the symbolic link folder in your project, that then references the latest active Flutter sdk version If you are using FVM, make sure you point the Flutter SDK path to the symbolic link folder in your project, that then references the latest active Flutter sdk version
Something like: C:\Dev\Flutter\TestFlutter\ .fvm\flutter_sdk类似于:C:\Dev\Flutter\TestFlutter\ .fvm\flutter_sdk
This is critical for it to work!这对于它的工作至关重要!
First thing I can imagine is the following.我能想到的第一件事是以下。
Check Flutter and Dart settings in Settings -> Language & Frameworks -> Flutter / Dart检查设置中的 Flutter 和 Dart 设置 -> 语言和框架 -> Flutter / Z35900D918789A83AF101ZDF
Make sure you use the proper flutter version and dart sdk comes from flutter/bin/cache/dart-sdk确保使用正确的 flutter 版本和 dart sdk 来自flutter/bin/cache/dart-sdk
For example my flutter is in C:\flutter and the dart-sdk's path is C:\flutter\bin\cache\dart-sdk例如,我的 flutter 在 C:\flutter 中,dart-sdk 的路径是 C:\flutter\bin\cache\dart-sdk
Solved: The problem is that the flutter path being used in the terminal of Android Studio was different to the flutter path in Preferences > Languages & Frameworks > Flutter
.已解决:问题是 Android Studio 终端中使用的 flutter 路径与
Preferences > Languages & Frameworks > Flutter
中的 flutter 路径不同。 I found this out by typing in the which flutter
command, which pointed to a different flutter path.我通过输入
which flutter
命令发现了这一点,该命令指向不同的 flutter 路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.