我要实现的效果是初始文本域显示一行,当内容超过一行时,文本域显示两行。问题是文本字段的基线会向下移动,导致它被下面的小部件遮挡。我希望基线保持连续。
代码:
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),
],
)
);
预期的效果应该是:
一行文字效果:
多行文字效果:
注意基线位置没有下移
最佳答案
只需将maxLines 属性设置为null。 TextField 小部件将自动换行文本,动态更改行数。
关于flutter - flutter如何让textfield动态显示多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51906919/