如何解决 Flutter 中与 TapDownDetails 和 TapDragDownDetails 相关的gesture_detector_builder.dart 中的参数类型错误?
:错误:无法将参数类型“void Function(TapDownDetails)”分配给参数类型“void Function(TapDragDownDetails)?”。
- “TapDownDetails”来自“package:flutter/src/gestures/tap.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/tap.dart”)。
- “TapDragDownDetails”来自“package:flutter/src/widgets/tap_and_drag_gestures.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart”)。 onTapDown:onTapDown, ^ :错误:参数类型“void Function(TapUpDetails)”无法分配给参数类型“void Function(TapDragUpDetails)?”。
- “TapUpDetails”来自“package:flutter/src/gestures/tap.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/tap.dart”)。
- “TapDragUpDetails”来自“package:flutter/src/widgets/tap_and_drag_gestures.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart”)。 onSingleTapUp:onSingleTapUp, ^ :错误:参数类型“void Function(TapDownDetails)”无法分配给参数类型“void Function(TapDragDownDetails)?”。
- “TapDownDetails”来自“package:flutter/src/gestures/tap.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/tap.dart”)。
- “TapDragDownDetails”来自“package:flutter/src/widgets/tap_and_drag_gestures.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart”)。 onDoubleTapDown:onDoubleTapDown, ^ :错误:参数类型“void Function(DragStartDetails)”无法分配给参数类型“void Function(TapDragStartDetails)?”。
- “DragStartDetails”来自“package:flutter/src/gestures/drag_details.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/drag_details.dart”)。
- “TapDragStartDetails”来自“package:flutter/src/widgets/tap_and_drag_gestures.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart”)。 onDragSelectionStart:onDragSelectionStart, ^ :错误:参数类型“void Function(DragStartDetails, DragUpdateDetails)”无法分配给参数类型“void Function(TapDragUpdateDetails)?”。
- “DragStartDetails”来自“package:flutter/src/gestures/drag_details.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/drag_details.dart”)。
- “DragUpdateDetails”来自“package:flutter/src/gestures/drag_details.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/drag_details.dart”)。
- “TapDragUpdateDetails”来自'package:flutter/src/widgets/tap_and_drag_gestures.dart' ('/C:/Flutter/flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart')。 onDragSelectionUpdate:onDragSelectionUpdate, ^ :错误:参数类型“void Function(DragEndDetails)”无法分配给参数类型“void Function(TapDragEndDetails)?”。
- “DragEndDetails”来自“package:flutter/src/gestures/drag_details.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/gestures/drag_details.dart”)。
- “TapDragEndDetails”来自“package:flutter/src/widgets/tap_and_drag_gestures.dart”(“/C:/Flutter/flutter/packages/flutter/lib/src/widgets/tap_and_drag_gestures.dart”)。 onDragSelectionEnd: onDragSelectionEnd, ^
失败:构建因异常而失败。
- 其中: 脚本“C:\Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle”行:1201
- 出错原因: 任务“:app:compileFlutterBuildDebug”执行失败。
Process 'command 'C:\Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1
- 尝试:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
- 在 https://help.gradle.org 获取更多帮助
构建在 1 分 50 秒内失败 E/AndroidRuntime(29997):致命异常: ScreenDecorations E/AndroidRuntime(29997):进程:com.android.systemui,PID:29997 E/AndroidRuntime(29997):java.lang.NullPointerException:指定为非空的参数为空:方法 kotlin.jvm.internal.Intrinsics.checkNotNullParameter,参数 bottomLeft E/AndroidRuntime(29997):位于 com.android.systemui.statusbar.events.PrivacyDotViewController.initialize(未知来源:22) E/AndroidRuntime(29997):位于 com.android.systemui.ScreenDecorations.setupDecorations(ScreenDecorations.java:315) E/AndroidRuntime(29997):位于com.android.systemui.ScreenDecorations.startOnScreenDecorationsThread(ScreenDecorations.java:252) E/AndroidRuntime(29997): 在 com.android.systemui.ScreenDecorations.$r8$lambda$bRx4s-frKyGv-SmpobluoualBbQ(未知来源:0) E/AndroidRuntime(29997): 在 com.android.systemui.ScreenDecorations$$ExternalSyntheticLambda2.run(未知来源:2) E/AndroidRuntime(29997): 在 android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(29997): 在 android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(29997): 在android.os.Looper.loopOnce(Looper.java:201) E/AndroidRuntime(29997): at android.os.Looper.loop(Looper.java:288) E/AndroidRuntime(29997): at android.os.HandlerThread.run(HandlerThread.java:67) 异常:Gradle 任务 assembleDebug 失败,退出代码为 1 已退出 (sigterm)
我想更新我的应用程序,所以我只更新了 flutter 和软件包。之后当我运行它时,会抛出上述错误。 这是我的 pubspec.yaml 包: http:^1.0.0 webfeed:0.7.0 xml:^5.4.1 cupertino_icons:1.0.5 flutter_launcher_icons:^0.11.0 shared_preferences:^2.1.1 share:2.0.4 launch_review:3.0.1 url_launcher:^6.1.11 fluttertoast:^8.2.2 font_awesome_flutter:10.4.0 webview_flutter:^2.3.4 flutter_html:2.2.1 percent_indicator:4.2.3 page_indicator:^0.4.1 admob_flutter:^3.0.0 flutter_local_notifications: ^12.0.4
我在将 Flutter 升级到 3.10.4 版本后遇到了此错误。 问题出在 flutter_html 包上。它依赖于 flutter_math_fork 0.5.0 ,它会抛出 Gesture_detector 错误。一旦我用不同的 HTML 渲染包替换 flutter_html ,错误就解决了
在您的终端上尝试以下命令:
- flutter clean
- flutter pub upgrade
- flutter pub outdated
- flutter pub upgrade --major-versions
- flutter pub get
然后运行它
我不知道为什么,经过 2/3 次
clean
和
get
之后,问题就解决了