光标通过表情符号

时间:2019-07-20 05:28:01

标签: 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);
});

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,以显示第一行以下行的表情符号行为有多困难。

enter image description here

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

编辑:CupertinoTextField没有此错误,所以我想在此问题解决之前,我会尝试

1 个答案:

答案 0 :(得分:0)

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