skip to Main Content

I’m using a TextField in Flutter and want to control the line wrapping behavior. How can I set the maxLines property or adjust the textInputAction and keyboardType to achieve this?

TextField(
  controller: _messageController,
  decoration: const InputDecoration(
    hintText: 'Type a message',
    border: InputBorder.none,
  ),
)

Using this code while typing, it’s continuing horizontally but I need to automatically make a new line once reached the end of the typing space available.

2

Answers


  1. Try below code…

              TextField(
                  controller: _messageController,
                  decoration: const InputDecoration(
                     hintText: 'Type a message',
                     border: InputBorder.none,
                     filled: true,
                     fillColor: Colors.grey,
                    ),
                  maxLines: null, 
                  keyboardType: TextInputType.multiline,
                  textInputAction: TextInputAction.newline, 
                ),
    
    Login or Signup to reply.
  2. Try using TextFormField instead of TextField

    TextFormField {
      controller: _messageController;
      decoration: const InputDecoration(
        hintText: 'Type a message',
        border: InputBorder.none,
      ),
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search