Make TextField wrap to a new line, not overflow

2,577

Solution 1

Unlimited number of lines

new TextField(..., maxLines: null)

or limited number of lines

new TextField(..., maxLines: 3)

This way it starts scrolling when the content exceeds the height of the input field

https://docs.flutter.io/flutter/material/TextField/maxLines.html

Solution 2

You have to set maxLines property to null. It default to 1.

Share:
2,577
haz
Author by

haz

Updated on December 04, 2022

Comments

  • haz
    haz over 1 year

    I am using a simple TextField wrapped in a Container. When the user types a long string, I want it to automatically wrap to a new line.

    It currently flows off the screen, on a single line. How do I fix this?

  • Can Rau
    Can Rau about 4 years
    Would be cool to have just a wrapText option to natively disallow line breaks and still prevent it from scrolling 🚀As a workaround I'm manually removing line-breaks on save using .replaceAll('\n', ' ')