当我在maxLines中将TextField设置为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,以显示第一行以下行的表情符号行为有多糟糕。
简而言之,只需将maxLines设置为TextField或TextFormField中的null即可。
编辑: CupertinoTextField没有这个bug,所以我想我会试一试,直到这是固定的
发布于 2019-07-24 02:38:12
这个问题是由颤振小组解决的。https://github.com/flutter/engine/pull/10063
https://stackoverflow.com/questions/57122054
复制