【问题标题】:pubspec.yaml has no lower-bound SDK constraintpubspec.yaml 没有 SDK 下限约束
【发布时间】:2021-05-13 19:55:57
【问题描述】:

我正在参加 MDC101 颤振代码实验室。我按照说明从 git 存储库中克隆了启动项目,但克隆完成后,我执行了flutter pub get,它给了我以下错误。

pubspec.yaml has no lower-bound SDK constraint.
You should edit pubspec.yaml to contain an SDK constraint:
environment:
  sdk: '>=2.10.0 <3.0.0'

【问题讨论】:

  • 只需将 environment: sdk: '>=2.10.0
  • 我已将 environment: sdk: '>=2.10.0

标签: flutter sdk flutter-web lower-bound flutter-pub


【解决方案1】:

即使您的 pubspec.yaml 文件包含正确的 sdk 行,如果您收到此错误,请务必检查主文件夹中的子文件夹。注意到在从 font_awesome_flutter 包中执行 flutter packages get 时会发生这种情况。原因是即使主 pubspec.yaml 包含正确的行,也有一个冒犯的example/pubspec.yaml。将这些行添加到该文件中:

environment:
  sdk: ">=2.7.0 <3.0.0"

Referenced issue.

【讨论】:

  • 这是问题之一。确实应该是公认的答案。
  • 在我的情况下,问题与“font_awesome_flutter”无关,而是来自“OneSignal-Flutter-SDK\example”的文件夹“example”,其中包含有问题的 pubspec.yaml。
  • 提示:一个flutter项目里面有两个pubspec.yaml文件,一个在“root”文件夹下,一个在“example/”文件夹下。我们必须将此行添加到两个文件中。
  • example/ 文件夹在哪里?
【解决方案2】:

根据错误说明,我在pubspec.yaml 中添加了以下内容

environment:
  sdk: '>=2.10.0 <3.0.0'

然后我执行了flutter pub get,它现在工作正常。

【讨论】:

    【解决方案3】:

    从 Dart 2.12 开始,省略 SDK 约束是一个错误。当 pubspec 没有 SDK 约束时,pub get 失败并显示如下消息:

    pubspec.yaml has no lower-bound SDK constraint.
    You should edit pubspec.yaml to contain an SDK constraint:
    (...)
    

    例如,以下约束说明此包适用于 2.10.0 或更高版本的任何 Dart SDK:

    environment:
      sdk: '>=2.10.0 <3.0.0'
    

    更多信息您可以查看docs

    【讨论】:

      【解决方案4】:

      用命令行检查你的颤振通道:

      flutter channel

      如果它在主频道,则切换到稳定频道:

      flutter channel stable

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-27
        • 2012-12-28
        • 2017-09-17
        • 2017-11-29
        • 1970-01-01
        • 1970-01-01
        • 2013-01-23
        • 1970-01-01
        相关资源
        最近更新 更多