当我在 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);
});
文本字段消失并显示以下日志:
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 没有这个错误,所以我想我会尝试直到这个问题被修复
最佳答案
此问题已由 Flutter 团队修复。 https://github.com/flutter/engine/pull/10063
关于android - 光标经过表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57122054/