Home > Mobile >  How to get newline character in TextField
How to get newline character in TextField

Time:07-14

I am using Stream chat API for the chat application. And while sending message I want to use the newline character in the textinput but I tried, the following code. It isn't working. And I am not finding any fixes, on the internet. Any help would be grateful appreciated.

                     child: TextField(
                          textInputAction: TextInputAction.newline,
                          keyboardType: TextInputType.multiline,
                          controller: controller,
                          onChanged: (val) {
                            StreamChannel.of(context).channel.keyStroke();
                          },
                          style: const TextStyle(fontSize: 14),
                          decoration: const InputDecoration(
                            hintText: 'Type something...',
                            border: InputBorder.none,
                          ),
                          onSubmitted: (_) => _sendMessage(),
                        ),

Edit : Solution

Adding maxLines:null solved the problem.

CodePudding user response:

In your TextField, add

   maxLines: null,

Or

   maxLines: 5,

whatever you want.

CodePudding user response:

When you hit the return or enter key the on submit _sendMessage() is called. Please try removing on submit and new line should work also make sure that the maxline is set to null so its not restricted to add any number of lines

  • Related