replacedText method

TextEditingValue replacedText(
  1. String newText
)

Implementation

TextEditingValue replacedText(String newText) {
  if (newText == text) {
    return this;
  }

  final rangeAfter = newText.getChangedRange(
    text,
    attributeChangeTo: TextAffinity.upstream,
  );

  return TextEditingValue(
    text: newText,
    selection: TextSelection.collapsed(offset: rangeAfter.start),
  );
}