简体   繁体   English

Flutter 说 Dart 版本是 2.13.4 即使它是 2.16.0

[英]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 路径。

在此处输入图像描述

check the current path of dart SDK in vscode在vscode中查看dart SDK当前路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter 医生说 Flutter 插件没有安装,即使我有 - Flutter doctor says flutter plugins not installed even though I have Dart 版本在更新 Flutter 后仍然相同 - Dart version is still same even after updating Flutter Flutter 和 Dart 插件在降级 flutter 时未安装错误,即使它们已安装在 ZC31B32364CE1EC5CA8FCD1508A 上 - Flutter and Dart plugin not installed errror when downgrade flutter even though they are installed on android studio 颤振较低的飞镖版本 - Flutter lower dart version flutter dart sdk版 - flutter dart sdk version Flutter 选项卡 - 即使未显示,也会创建一个选项卡 - Flutter tabs - a tab is created even though it's not displayed 因为项目要求SDK版本>=2.14.0 <3.0.0,所以即使Dart SDK版本是2.14.0-350.0.dev也解决不了版本问题 - Because project requires SDK version >=2.14.0 <3.0.0, version solving failed even though Dart SDK version is 2.14.0-350.0.dev 在 Flutter 中出现“未引用声明”错误,即使它在 main.dart 中被引用 - Getting “The Declaration Isn't Referenced” error in Flutter even though it is referenced in main.dart Flutter安装Dart版本SDK为1.24.3-不是Dart 2 - Flutter install Dart version SDK is 1.24.3 - not Dart 2 Android Studio 说 Flutter 和 Dart 插件已安装,但 ZC047B10EEE763AFB6164E077CF1 医生说它们不是 - Android Studio says Flutter and Dart plugins are installed, but Flutter Doctor says they are not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM