【问题标题】:Flutter Error on line 6, column 5 of pubspec.yaml: A dependency may only have one source. sdk: flutter ^^^^^^^^^^^^^pubspec.yaml 第 6 行第 5 列的 Flutter 错误:依赖项可能只有一个源。 sdk:颤振^^^^^^^^^^^^^
【发布时间】:2018-09-03 15:05:02
【问题描述】:

我不断得到

Running "flutter packages get" in flutter_sportters...
Error on line 6, column 5 of pubspec.yaml: A dependency may only have one source.
    sdk: flutter
    ^^^^^^^^^^^^^

当我运行my appPackages Get 时。

它以前工作得很好。不知道如何解决这个问题。

【问题讨论】:

  • 欢迎来到SO,请阅读:stackoverflow.com/help/how-to-ask
  • 非常感谢。我读了它,并将自己保留它!
  • 您的pubspec.yaml 文件中可能有一个缩进。请张贴出来以便我们检查。
  • 请在您的回答中发布您的pubspec.yaml

标签: flutter


【解决方案1】:

考虑你将使用这个包“shared_preferences”。

您将在 pubspec.yaml 中收到此错误。如果您喜欢下面的内容。

dependencies:
 flutter:
  sdk: flutter
  shared_preferences: v0.4.2

缩进很重要,你不小心在flutter依赖项下添加了shared_preference包。所以报错“A dependency may only have one source”

以下格式正确:

dependencies:
 flutter:
  sdk: flutter

 shared_preferences: v0.4.2 #no indention

【讨论】:

  • 哇。刚刚回想起 80 列编码板和 IBM 029,我使用的是 70 年代。
【解决方案2】:

由于 Indention 会引发错误。在 Flutter 中添加依赖项的同时保持缩进很重要。

之前:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  english_words: ^3.1.0

之后:

dependencies:
  flutter:
    sdk: flutter

cupertino_icons: ^0.1.2
english_words: ^3.1.0

希望这能解决您的错误。 编码快乐!!!

【讨论】:

    【解决方案3】:

    缩进!!! 作为新手犯愚蠢的错误。我在颤振根中编写了新的依赖项:

    dependencies:
      flutter:
        sdk: flutter
        sqflite: 
    

    而不是

    dependencies:
      flutter:
        sdk: flutter
      sqflite: 
    

    看到差异时发表评论!

    【讨论】:

    • 看到了不同
    【解决方案4】:

    我试图将assets 文件夹添加到我的项目中。我在dependencies 下添加了它导致错误:

    dependencies:
      flutter:
        sdk: flutter
        assets:
          - images/
    

    dependencies 下不可添加。而是将其添加到flutter

    flutter:
      uses-material-design: true
      assets:
        - images/
    

    【讨论】:

    • 谢谢!尽管在 pubspec 样板代码中的 cmets 中提到了这一点,但很容易不时错过并滑倒。
    【解决方案5】:

    你可以像在 pubspec.yaml 文件中那样定义

    dependencies:
      flutter:
        sdk: flutter
      image_picker: 0.4.1
    

    flutter 包获取,您可以通过终端调用,或者如果您使用的是 Android Studio,则在编辑 pubspec.yaml 文件时可以使用上述选项。

    终端进入你的项目目录然后输入flutter packages get

    【讨论】:

      【解决方案6】:

      我解决了我的问题:

      这是我的第一个代码

      dependencies
      flutter:
          sdk: flutter
          webfeed: ^0.4.2
      
        # The following adds the Cupertino Icons font to your application.
        # Use with the CupertinoIcons class for iOS style icons.
        cupertino_icons: ^0.1.2
      

      修改后

      dependencies:
        flutter:
          sdk: flutter
      
        webfeed: ^0.4.2
      
        # The following adds the Cupertino Icons font to your application.
        # Use with the CupertinoIcons class for iOS style icons.
        cupertino_icons: ^0.1.2
      

      我觉得你必须把你的包名放在flutter:cupertino_icons:的同一个数字列中

      【讨论】:

      • 谢谢。我犯了这个错误。用flutter内联编写新包:解决了这个问题。
      【解决方案7】:

      打开你的 pubspec.yaml 文件

      dependencies:
        flutter:
          sdk: flutter
      
        cupertino_icons: ^0.1.2
        country_code_picker: ^1.0.4
      

      【讨论】:

        【解决方案8】:

        其他答案是正确的。我还想补充一点,我正在尝试添加shared_preferences,即使我的缩进是正确的,我仍然收到问题中提到的错误。为了解决它,我更改了我的项目名称,因为它也是 shared preferences

        【讨论】:

          【解决方案9】:

          无论我做什么,包括注释掉新行,我都会不断收到这个错误。最后,我用正确的缩进将它们放回原处并运行程序。这个问题神奇地解决了。但是,缩进很关键。

          【讨论】:

            【解决方案10】:

            由于依赖项中的包重复,我收到此错误 IE: 依赖:

            颤动: sdk:颤动

            **cupertino_icons: ^0.1.2**
              english_words: ^3.1.5
            

            # 下面将 Cupertino Icons 字体添加到您的应用程序中。 # 与 CupertinoIcons 类一起用于 iOS 样式图标。

            cupertino_icons:^0.1.2

            我通过删除重复然后 Flutter clean 然后 Flutter Packages Get 解决了这个错误。

            【讨论】:

              【解决方案11】:

              这是由于缩进:检查正确的方式

              名称:flutter_app 描述:一个新的 Flutter 应用程序。

              环境: sdk: ">=2.1.0

              依赖: 扑: sdk:颤动 http:“0.11.3+17” 自动完成文本字段:^1.6.4

              dev_dependencies: 颤振测试: sdk:颤动

              颤动: 使用材料设计:是的

              【讨论】:

                【解决方案12】:

                我遇到了同样的问题,原来我的应用程序名称和包名称相同导致了这个错误。

                应用程序的名称scrapy和依赖也是scrapy...

                改了名字就行了。

                【讨论】:

                  【解决方案13】:

                  检查所有其他解决方案后,如果问题仍然存在 确保指定的库是否安装正确。当库未正确安装时也会遇到此错误。

                  【讨论】:

                    【解决方案14】:

                    检查缩进,因为 pubspec.yaml 中的颤振包采用单一依赖源。

                    【讨论】:

                      【解决方案15】:

                      确保您的项目名称与任何包的名称不同, 这也是导致此错误的原因

                      【讨论】:

                      猜你喜欢
                      • 1970-01-01
                      • 2021-07-18
                      • 1970-01-01
                      • 2020-06-30
                      • 1970-01-01
                      • 2021-01-26
                      • 2020-02-17
                      • 2020-01-23
                      • 1970-01-01
                      相关资源
                      最近更新 更多