使用新的 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
我试过用以前的版本替换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时,只需要包含一个依赖即可
您似乎包括了 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 依赖冲突。重命名您的项目,它将起作用。
我遇到了这个问题。这是因为我将 name: riverpod 放入我的 pubspec.yaml 文件中。我可以看到你也犯了同样的错误。更改名称并尝试。希望大家节省时间。
好吧,我是这个 riverpod 方面的新手,现在这个答案对我没有任何作用,直到我记得我已经错误地安装了 riverpod(pure-dart),然后我从 pubs.yml
中删除了该依赖项并且添加了 flutter-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
现在因为这只是学习项目,所以我能够创建一个新的应用程序然后安装 flutter_riverpod: ^0.14.0+3 然后它没有任何问题地工作。
如果有人面临同样的问题,请尝试 flutter clean
然后 运行 再次应用程序而不调试然后希望一切正常,或者如果您仍然像我一样学习创建一个新的应用程序
我认为即使我们从 pubs.yml
中删除了依赖项,那里仍然有一些记录,所以混淆了包安装程序