首页 > 解决方案 > Flutter (graphql_flutter + gql):找到了这个候选人,但参数不匹配

问题描述

尝试构建应用程序(iOS)时,得到以下输出:

删除graphql_flutter应用程序内的引用可以消除这些错误。

我已经尝试了 Flutter 的每一个通道,但问题仍然存在。

../../../flutter/.pub-cache/hosted/pub.dartlang.org/graphql-5.0.0/lib/src/core/query_manager.dart:427:23: Error: Required named parameter 'response' must be provided.
              Response(data: cachedData),
                      ^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/gql_exec-0.3.2-alpha+1635885531651/lib/src/response.dart:23:9: Context: Found this candidate, but the arguments don't match.
  const Response({
        ^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/gql_link-0.4.0/lib/src/response_parser.dart:10:64: Error: Required named parameter 'response' must be provided.
  Response parseResponse(Map<String, dynamic> body) => Response(
                                                               ^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/gql_exec-0.3.2-alpha+1635885531651/lib/src/response.dart:23:9: Context: Found this candidate, but the arguments don't match.
  const Response({
        ^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/gql_http_link-0.4.0/lib/src/link.dart:128:19: Error: Required named parameter 'response' must be provided.
    yield Response(
                  ^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/gql_exec-0.3.2-alpha+1635885531651/lib/src/response.dart:23:9: Context: Found this candidate, but the arguments don't match.
  const Response({

来自 pubspec.yaml:

graphql_flutter: ^5.0.0
gql: ^0.13.0

来自flutter doctor(尚未设置Android)

[✓] Flutter (Channel stable, 2.5.3, on macOS 11.5.2 20G95 darwin-x64, locale en-US)
    • Flutter version 2.5.3 at /Users/justin/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (3 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/justin/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.0, Build version 13A233
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] VS Code (version 1.61.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.27.0

[✓] Connected device (2 available)
    • iPhone 13 (mobile) • BB5BF139-9146-4AC0-8316-7D044BD283B8 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 95.0.4638.69

! Doctor found issues in 1 category.

标签: flutterdart

解决方案


TLDR;此问题是由于 gql_exec 包含有关依赖库尚未实现的参数的非常近期的重大更改。

要解决此问题,请使用以下方法之一:

  • 在您的 pubspec.lock 文件中使用下面的代码片段,并且在库之间解决此重大更改之前不要运行升级。(最快的解决方案)
  • 使用固定版本,直到依赖库支持此功能。(更好但更慢的解决方案)
  • gql_exec 更新他们的代码以确保这不是使用 PATCH 编号的重大更改(请参阅:SEMVER)。(最佳解决方案,但可能需要一段时间)

从我们的 pubspec.lock 文件中参考,我们使用以下版本构建

gql:
    dependency: "direct main"
    description:
      name: gql
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.13.1-alpha+1633799193898"
  gql_build:
    dependency: "direct dev"
    description:
      name: gql_build
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.3.0-alpha+1633799193977"
  gql_code_builder:
    dependency: transitive
    description:
      name: gql_code_builder
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.3.0-alpha+1633799193964"
  gql_dedupe_link:
    dependency: transitive
    description:
      name: gql_dedupe_link
      url: "https://pub.dartlang.org"
    source: hosted
    version: "2.0.0"
  gql_error_link:
    dependency: transitive
    description:
      name: gql_error_link
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.2.0"
  gql_exec:
    dependency: transitive
    description:
      name: gql_exec
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.3.1-alpha+1633799193908"
  gql_http_link:
    dependency: transitive
    description:
      name: gql_http_link
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.4.0"
  gql_link:
    dependency: transitive
    description:
      name: gql_link
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.4.0"
  gql_transform_link:
    dependency: transitive
    description:
      name: gql_transform_link
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.2.0"
  gradient_widgets:
    dependency: "direct main"
    description:
      name: gradient_widgets
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.6.0"
  graphql:
    dependency: transitive
    description:
      name: graphql
      url: "https://pub.dartlang.org"
    source: hosted
    version: "5.0.0"
  graphql_flutter:
    dependency: "direct main"
    description:
      name: graphql_flutter
      url: "https://pub.dartlang.org"
    source: hosted
    version: "5.0.0"

如果您想深入了解这一点,请参阅以下提交中的文件 links/gql_exec/lib/src/response.dart 第 27 行,其中添加了新参数并根据需要声明。 https://github.com/gql-dart/gql/commit/8699d2fcc285789ec6e891b034e98fd2b7750296#diff-99580a029d7aed82312588b8cda13419bc8f9c0e58ac97e1f7bcdad51fc39c10R27


推荐阅读