Reputation: 397
The effect I want to achieve is that the initial text field displays one line, and when the content exceeds one line, the text field displays two lines. The problem is that the baseline of the text field will move down, causing it to be obscured by the widget below. I want the baseline to remain in a row.
code:
return Scaffold(
appBar: AppBar(),
body: Column(
children: <Widget>[
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 60.0
),
child: TextField(
maxLines: null,
maxLengthEnforced: false,
keyboardType: TextInputType.multiline,
),
),
Container(height: 20.0,width: 200.0,color: Colors.red),
],
)
);
The expected effect should be:
One line of text effect:
Multi-line text effect:
Note that the baseline position has not moved down.
Upvotes: 1
Views: 6215
Reputation:
Just set the maxLines property to null. The TextField Widget will automatically wrap the text, changing the number of lines dynamically.
Upvotes: 15