0

After selecting the whole text in a TextField using TextSelection() it does indeed select the whole text but after pressing a key on the keyboard, it starts adding pressed letters/numbers to the start of the text as opposed to deleting the old one and replacing it with the newly typed letters/numbers.

Is this expected behavior? If so, is there any way I can programatically select the text and then replace it upon pressing a key on the keyboard?

This is how I select the text:

manualEditorNode.addListener(() {
  if (manualEditorNode.hasFocus) {
    manualInputController.selection = TextSelection(
        baseOffset: 0, extentOffset: manualInputController.text.length);
  }
});
user6704969
  • 21
  • 1
  • 5

1 Answers1

0

The following works for me in my program. Maybe you can try something like this?

var cursorPos = textInputController.selection;
setState(() {
  textInputController.text = newInput;

  if (cursorPos.start > newInput.length) {
    cursorPos = new TextSelection.fromPosition(
        new TextPosition(offset: newInput.length));
  }
  textInputController.selection = cursorPos;
});
Herman
  • 1,882
  • 3
  • 14
  • 17