【问题标题】:Cursor is passing through emoji光标正在通过表情符号
【发布时间】:2019-11-29 00:21:23
【问题描述】:

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

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

光标经过的表情符号会变成无效字符。

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);
});

TextField 消失并显示以下日志:

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 来显示表情符号行为对于第一行以下的行有多么错误。

简单来说就是在TextField或者TextFormField中设置maxLines为null就可以看到这个效果了。

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

【问题讨论】:

    标签: android ios flutter dart


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 2019-05-04
      • 1970-01-01
      • 2021-12-30
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多