前置条件
- Flutter 版本: 3.27.0 / 3.27.1
- Dart 版本: 3.6.0
- 编译器: Android Studio Ladybug | 2024.2.1 Patch 3
- 操作系统: macOS Sequoia 15.2 (Apple M2) / Windows 11 专业版 23H2
- 浏览器: Chrome (131.0.6778.205)
问题描述
直接从 Flutter API 官方页面(Form Class Documentation)复制 Form 示例,并使用 Flutter 的 Web 调试模式运行。
尝试用鼠标单击文本输入时,遇到以下错误:
1 2 3 4 5 6 7 8 9 10 11 12 |
DartError: Assertion failed: org-dartlang-sdk:///lib/_engine/engine/pointer_binding/event_position_helper.dart:70:10 targetElement == domElement "The targeted input element must be the active input element" dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:3 throw_ dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 110:39 assertFailed dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 110:39 _computeOffsetForInputs lib/_engine/engine/pointer_binding/event_position_helper.dart 38:14 computeEventOffsetToTarget lib/_engine/engine/pointer_binding.dart 1088:30 [_convertEventsToPointerData] lib/_engine/engine/pointer_binding.dart 1016:9 <fn> lib/_engine/engine/pointer_binding.dart 948:7 <fn> lib/_engine/engine/pointer_binding.dart 541:9 loggedHandler dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 212:27 _callDartFunctionFast1 |
这个问题是 Flutter 3.27.0 / 3.27.1 的缺陷,官方已经在 Flutter 3.28 版本修复,后续升级到 Flutter 3.28 即可解决此问题。
参考链接
- Flutter Web 调试问题:Chrome 中文本输入点击断言失败(Flutter 3.27.0、Dart 3.6.0)
- Flutter web 3.27 debug - TextFormField - DartError event_position_helper.dart:70:10 - The targeted input element must be the active input element #160155
- Flutter Web Debugging Issue: Assertion Failed on Text Input Click in Chrome (Flutter 3.27.0, Dart 3.6.0)