-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
A common UI pattern is having a text field which grows vertically, adding more lines, as you type, up to a certain number of lines, after which the content scrolls.
Presently, we can have a growing TextField by making maxLines=null. However, then the TextField never stops growing. Otherwise, if we make, say, maxLines=6, then it will have 6 fixed lines, and will not grow.
Unfortunatelly, maxLines was a bad name. That should have been called simply "lines", since it fixes the number of lines, and is not a maximum. However, that cannot be changed anymore.
I will now suggest adding another parameter, called maxLineLimit, which lets the number of lines grow until that number and then no more. And while we're at that, I would also add the less important minLineLimit.
So, for example, if we make maxLines=null, minLineLimit=2, maxLineLimit=6, then the TextField starts with 2 lines, and, if necessary to fit the text, grows until 6 lines. After that it scrolls.
This change is very easy to do, in file editable.dart, the method _preferredHeight in class RenderEditable has these last 2 lines:
_layoutText(width);
return math.max(preferredLineHeight, _textPainter.height);These could be simply changed to:
_layoutText(width);
return math.min(preferredLineHeight * maxLineLimit, math.max(preferredLineHeight * minLineLimit, _textPainter.height));