addText method
在光标位置添加文字,一般用于键盘输入
Implementation
addText(String insertText){
realText = realText.length == 0 ? (value.text == hideChar * value.text.length ? CoolKeyboard.text: value.text):realText;
String newText = selection.textBefore(text) + insertText + selection.textAfter(text);
realText = selection.textBefore(realText) + insertText + selection.textAfter(realText);
if(isPassword) {
newText = hideChar * newText.length;
}
value = TextEditingValue(
text: newText,
selection: selection.copyWith(
baseOffset:selection.baseOffset + insertText.length,
extentOffset: selection.baseOffset + insertText.length)
);
}