如何在 VSCode/flutter 中升级包?

gkd*_*720 7 visual-studio-code flutter

我在 Flutter 项目中使用 VS Code。我刚刚编辑了 pubspec.yaml 以指向包的更高版本,它会自动运行“flutter packages get”。在我的 '/development//flutter/.pub-cache/hosted/pub.dartlang.org' 目录中,我可以看到两个版本。但是我编译的时候,好像还在用老版本。我尝试了各种方法,例如“颤振包升级”、“颤振清洁”等,但无济于事。查看 2 个包版本的源代码,我可以在较新的版本中看到我想要的更改。如何指向新包?谢谢。

更新:

这是没有更新的“以太坊”包。我曾经使用过 3.0.0 版本(方法需要 2 个参数),然后切换到 3.1.0 版本(方法需要 3 个参数)。但是使用 3 个 arg 调用编译时参数计数不正确:

client.admin.personalSendTransaction(BigInt.parse(currentAddress), currentPassword,{});

[dart] Too many positional arguments: 2 expected, but 3 found. [extra_positional_arguments_could_be_named]
Run Code Online (Sandbox Code Playgroud)

然而,将鼠标悬停在方法调用上确实显示它需要 3 个参数:

personalSendTransaction(BigInt address, String passphrase, {BigInt to, BigInt data, int gas, int gasPrice, int value, int nonce, int condition, bool conditionIsTimestamp: false}) ? Future<BigInt>
Run Code Online (Sandbox Code Playgroud)

pubspec.yaml:

    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: ^0.1.2

  # Get package(s) for talking to ethereum node
  # web3dart: '>=0.3.0'
  ethereum: ^3.1.0

  # read barcodes and QR codes
  barcode_scan: ^0.0.3

  # Generate a QR code
  qr: ^1.0.1

  # Display as actual symbol
  qr_flutter: ^1.1.5

dev_dependencies:
  flutter_test:
    sdk: flutter
Run Code Online (Sandbox Code Playgroud)

在 pubspec.lock 中:

  ethereum:
    dependency: "direct main"
    description:
      name: ethereum
      url: "https://pub.dartlang.org"
    source: hosted
    version: "3.1.0"
Run Code Online (Sandbox Code Playgroud)

3.1.0版本是我想用的。

运行“颤振包升级已解决”会产生:

[Gregorys-iMac]:(gkd) ~/Programs/wine_track $ flutter packages upgrade resolved
Running "flutter packages upgrade" in ....                   2.7s
Run Code Online (Sandbox Code Playgroud)

在包缓存中,我有两个:

/Users/gkd/development//flutter/.pub-cache/hosted/pub.dartlang.org/ethereum-3.0.0/lib/src/api/ethereum_api_admin.dart

/Users/gkd/development//flutter/.pub-cache/hosted/pub.dartlang.org/ethereum-3.1.0/lib/src/api/ethereum_api_admin.dart
Run Code Online (Sandbox Code Playgroud)

小智 57

flutter pub upgrade --major-versions
Run Code Online (Sandbox Code Playgroud)


gee*_*ano 12

您可以简单地flutter packages upgrade在您的项目中运行以升级所有包。此功能从 Flutter 1.17 版开始可用


Ana*_*nan 7

只需使用

flutter pub upgrade --major-versions
Run Code Online (Sandbox Code Playgroud)

或者

flutter packages upgrade
Run Code Online (Sandbox Code Playgroud)


gkd*_*720 0

好吧,那算了。这是我的错误。我将声明的“{ type:variablename, . . .}”解释为映射/哈希。实际上,它们是 Dart 的可选命名参数。只需使用其中任何一个而不使用大括号即可编译干净。