0

I have a TextField like this:

TextField(
  controller: _controller,
  ..
)

Where _controller is a TextEditingController. From outside my TextField. I have an emoji selector. When an emoji is selected, I want to append it to the controller's text, but there's no function like _controller.addText(emoji). How can I insert something into the controller's text? Assuming there might be stuff typed before, or after I insert the emoji.

Peter R
  • 3,185
  • 23
  • 43
  • I have the same question as I was about to make the "PETER ANSWERS" project in a flutter. As the functionality I have to add the "Peter please answer" sentence after pressed the specific key like a "." – Kishan Dhankecha May 11 '21 at 03:26

1 Answers1

1

_controller.text += emoji; should do it.

S. M. JAHANGIR
  • 4,324
  • 1
  • 10
  • 30
  • Hmm, that does work, thanks! However it resets the cursor to the beginning of the text. Is there a way to fix that? – Peter R May 11 '21 at 00:16
  • For more advanced workaround, you can refer to this: https://stackoverflow.com/questions/60057840/flutter-how-to-insert-text-in-middle-of-text-field-text – S. M. JAHANGIR May 11 '21 at 03:23