maxLines property Null safety

int? maxLines

The maximum number of lines for the text to span, wrapping if necessary.

If this is 1 (the default), the text will not wrap, but will scroll horizontally instead.

If this is null, there is no limit to the number of lines, and the text container will start with enough vertical space for one line and automatically grow to accommodate additional lines as they are entered.

If this is not null, the value must be greater than zero, and it will lock the input to the given number of lines and take up enough horizontal space to accommodate that number of lines. Setting minLines as well allows the input to grow between the indicated range.

The full set of behaviors possible with minLines and maxLines are as follows. These examples apply equally to TextField, TextFormField, and EditableText.

Input that occupies a single line and scrolls horizontally as needed.


Input whose height grows from one line up to as many lines as needed for the text that was entered. If a height limit is imposed by its parent, it will scroll vertically when its height reaches that limit.

TextField(maxLines: null)

The input's height is large enough for the given number of lines. If additional lines are entered the input scrolls vertically.

TextField(maxLines: 2)

Input whose height grows with content between a min and max. An infinite max is possible with maxLines: null.

TextField(minLines: 2, maxLines: 4)


final int? maxLines;