insert method
Implementation
void insert(String s) {
if (s.isEmpty) return;
TextEditingValue v = this.value;
if (this.text.isEmpty) {
this.value = TextEditingValue(
text: s,
selection: TextSelection.collapsed(offset: s.length),
);
return;
}
String oldText = this.text;
TextSelection old = v.selection;
if (old.isValid && old.isNormalized) {
String newText = old.textBefore(oldText) + s + old.textAfter(oldText);
int newStart = old.start + s.length;
this.value = TextEditingValue(
text: newText,
selection: TextSelection.collapsed(offset: newStart),
);
}
}