I'm working on a Flutter Web application which includes chat.
I'd like to include an ordinary input function where users can enter text and send it into the chat stream. A standard feature of chat apps these days is to send
on <ENTER>
and to perform a line break on <SHIFT-ENTER>
, or some variation of this.
Currently I've only been able to achieve one of these functions at a time. If you set the TextField
's keyboardType
to TextInputType.multiline
then <ENTER>
and <SHIFT-ENTER>
always perform a line-break, there doesn't appear to be a way to override this behavior.
If instead your TextField
is TextInputType.text
you can capture <ENTER>
and send, but trying to capture <SHIFT-ENTER>
to add a line-break has not worked. I've tried manually grabbing the key press via an onKey
handler and inserting \n
to the controller.text
, but it appears that TextInputType.text
is not meant for multiline at all, so it doesn't play well.
Just wondering if any other devs have run into this or come up with any suitable solutions. Ideally a solution would also work across android/ios. For me, I've decided to go with TextInputType.text
and forgo the multiline functionality for now.
Thanks