// Get cursor current position
var cursorPos =
_textEditController.selection.base.offset;
// Right text of cursor position
String suffixText =
_textEditController.text.substring(cursorPos);
// Add new text on cursor position
String specialChars = ' text_1 ';
int length = specialChars.length;
// Get the left text of cursor
String prefixText =
_textEditController.text.substring(0, cursorPos);
_textEditController.text =
prefixText + specialChars + suffixText;
// Cursor move to end of added text
_textEditController.selection = TextSelection(
baseOffset: cursorPos + length,
extentOffset: cursorPos + length,
);
2条答案
按热度按时间bf1o4zei1#
我解决了这个问题;
nzrxty8p2#
简单地得到光标的位置和分裂它的firstpart和secondpart添加文本什么你想要插入
控制器.text=第一部分+“某个文本”+最后部分;