使用新的 Flutter 2.2.2 版本为 Riverpod 运行“flutter pub get”时版本解决失败

Posted

技术标签:

【中文标题】使用新的 Flutter 2.2.2 版本为 Riverpod 运行“flutter pub get”时版本解决失败【英文标题】:Version solving failing on running "flutter pub get" for Riverpod with the new Flutter 2.2.2 verison 【发布时间】:2021-08-20 03:01:41 【问题描述】:

我尝试用以前的版本替换 Riverpod 的版本,但没有任何效果。我也尝试过删除 pubspec.lock 文件,运行 flutter clean 命令等,但没有任何效果。如果使用flutter 2.2.2的人能够使用riverpod(任何版本),那么请帮助。

pubspec.yaml 文件:

name: riverpod
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

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In ios, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  flutter_riverpod: ^0.14.0+3

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg
  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.
  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages
  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

我附上下面的输出:

Running "flutter pub get" in riverpod...                        
Because riverpod depends on flutter_riverpod ^0.14.0+3 which depends on riverpod ^0.14.0+3, riverpod ^0.14.0+3 is required.
So, because riverpod is 1.0.0+1, version solving failed.

pub get failed (1; So, because riverpod is 1.0.0+1, version solving failed.)
exit code 1```

【问题讨论】:

你的项目名为riverpod,它依赖于flutter_riverpod,而flutter_riverpod本身又依赖于riverpod(发布的那个)。可以想象,这会让解析器感到困惑。您需要更改项目的名称。 【参考方案1】:

使用riverpod时,只需要包含一个依赖即可。

看来您正在包括riverpod flutter_riverpod。

相反,只使用flutter_riverpod。

为了明确这一点:

有效的 pubspec.yaml 用于:

纯飞镖:

dependencies:
  riverpod: ^0.14.0

非钩子:

dependencies:
  flutter_riverpod: ^0.14.0

钩子:

dependencies:
  hooks_riverpod: ^0.14.0

可以通过flowchart in the docs查看此信息。

编辑:您的具体问题是因为您的项目名为riverpod。它与 hooks_riverpod 和 flutter_riverpod 的 Riverpod 依赖冲突。重命名您的项目,它会工作。

【讨论】:

我只使用了一个依赖项“flutter_riverpod”,但问题仍然存在。 更新了我的答案。 非常感谢。真是个愚蠢的错误……从我的脑海中溜走?【参考方案2】:

我遇到了这个问题。这是因为我将 name:riverpod 放在了我的 pubspec.yaml 文件中。我可以看到你也犯了同样的错误。换个名字试试。希望您节省时间。

【讨论】:

是的,你是对的。我有同样的问题。现在排序:)【参考方案3】:

好的,我是这个riverpod方面的新手,现在这个答案对我不起作用,直到我记得我已经错误地安装了riverpod(pure-dart)然后我从pubs.yml中删除了该依赖项并添加了flutter-riverpod然后是同样的错误

因为 riverpod 依赖于 flutter_riverpod ^0.14.0+3 这取决于 在riverpod ^0.14.0+3 上,需要riverpod ^0.14.0+3

现在因为这只是一个学习项目,我能够创建一个新应用程序,然后安装 flutter_riverpod: ^0.14.0+3 然后它可以正常工作。

如果有人遇到同样的问题,请尝试flutter clean,然后在不调试的情况下再次运行应用程序,那么希望一切正常,或者如果您仍然像我一样学习,只需创建一个新应用程序

我认为即使我们从 pubs.yml 中删除了依赖项,那里仍然有一些记录,因此包安装程序令人困惑

【讨论】:

以上是关于使用新的 Flutter 2.2.2 版本为 Riverpod 运行“flutter pub get”时版本解决失败的主要内容,如果未能解决你的问题,请参考以下文章

如何在同一设备上为不同的项目使用两个版本的颤振?

Flutter-布局

Flutter 2:颜色问题

Flutter 简易入门(没有放弃)

Flutter 是不是适用于任何 Android 平台版本?

根据麻省理工学院的许可发布的开源文件管理器。PHP连接器的最新版本。此程序包已弃用。现在,请使用RichFileManager,网址为:https://github.com/servocoder/Ri