[ad_1]
While this question is rather old, there is no extensive answer that explains how to dynamically resize the TextField
with little developer effort. This is especially of major importance when the TextField
is either placed in a flexbox such as ListView, SingleChildScrollView, etc. (the flexbox will not be able to determine the intrinsic size of an expandable TextField
).
As suggested by many other users, build your TextField
like so:
TextField(
textInputAction: TextInputAction.newline,
keyboardType: TextInputType.multiline,
minLines: null,
maxLines: null, // 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.
expands: true, // If set to true and wrapped in a parent widget like [Expanded] or [SizedBox], the input will expand to fill the parent.
)
How to cope with the missing intrinsic height of the TextField
?
Wrap the TextField
in a IntrinsicHeight
class to provide the dynamically computed intrinsic height of the expandable TextField
to its parent (when requested via e.g. flexbox).
[ad_2]