android - 光标经过表情符号

标签 android ios flutter dart

当我在 TextField 中将 maxLines 设置为 null 时,对于第一行下方的表情符号,如果您点击表情符号的中心,光标将穿过中心。

enter image description here

当我添加新的表情符号时,会发生以下情况:

enter image description here

光标经过的表情符号会分解为无效字符。

这是 TextField 的代码:

TextEditingController _commentTextController = TextEditingController();


TextField(
  textInputAction: TextInputAction.send,
  keyboardType: TextInputType.multiline,
  cursorWidth: 1,
  autocorrect: false,
  cursorColor: Colors.black,
  controller: _commentTextController,
  maxLines: null,
  autofocus: true,
  decoration: InputDecoration(
    hintText: "Your comment...",
    enabledBorder: InputBorder.none,
    focusedBorder: InputBorder.none,
  ),
  style: TextStyle(fontSize: 15),
)

当我尝试使用以下代码在 TextField 中提取并设置新文本时:

String currentComment = _commentTextController.text;

String newCommentText = currentComment + "😂"

setState(() {
  _commentTextController = TextEditingController(text: newCommentText);
});

文本字段消失并显示以下日志:

I/flutter (27958): Another exception was thrown: Invalid argument(s): string is not well-formed UTF-16
I/flutter (27958): Another exception was thrown: NoSuchMethodError: The getter 'alphabeticBaseline' was called on null.
I/flutter (27958): Another exception was thrown: NoSuchMethodError: The method 'getBoxesForRange' was called on null.
I/flutter (27958): Another exception was thrown: Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.

我添加了下面的 gif,以显示第一行以下的行的表情符号行为有多么错误。

enter image description here

简而言之,只需在 TextField 或 TextFormField 中将 maxLines 设置为 null 即可看到此效果。

编辑:CupertinoTextField 没有这个错误,所以我想我会尝试直到这个问题被修复

最佳答案

此问题已由 Flutter 团队修复。 https://github.com/flutter/engine/pull/10063

关于android - 光标经过表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57122054/

相关文章:

ios - Xcode 7.0 XCTest dyld : could not load inserted library IDEBundleInjection

ios - PopoverPresentationController 委托(delegate)方法未调用

ios - 使用 OpenCV 改进已知对象检测性能

Flutter SizeTransition 和 PageRouteBuilder 不工作

android - AlertDialog 不会在我的应用程序中显示 - 为什么会这样?

android - 如何为 HoloColorPicker 不透明度栏设置默认颜色?

android - 如何使用默认的 android Button 可绘制作为另一个 View 的背景?

android - 为什么右键不能像左键一样在父级的右边

android - 类型 'Null' 不是类型 'Function' 的子类型

flutter - Flutter Youtube风格图像黑色叠加