有什么方法可以增加 flutter 中的文本字段标签宽度,以避免省略号 (...)?
标签始终小于文本字段区域。
我能想到的改善这一点的方法是减少内容填充的“开始”和“结束”,但效果很小。
child: TextField(
decoration: InputDecoration(
labelText: "em Dólares",
labelStyle: TextStyle(color: Colors.amber[600],
fontStyle: FontStyle.italic),
border: OutlineInputBorder(),
fillColor: Colors.black12,
filled: true,
contentPadding: EdgeInsetsDirectional.only(top: 20.0, bottom: 20.0, start: 5.0, end: 5.0), //<-- weak solution
prefixText: "US\$"),
style: TextStyle(color: Colors.amber[600], fontSize: 20.0),
)
Ps:我在上面的代码中隐藏了文本字段中一些不必要的属性,如控制器、inputFormatters、keyboardType。
要更改(减少/增加)标签的字体大小,您可以使用
fontSize:
中的 TextStyle()
属性。只需将字体大小添加到标签即可。
使用
fontSize
中的labelStyle
属性缩小标签文本的字体大小。如果标签的文本超过文本字段大小的一半,Flutter 将显示省略号(我在文档中找不到这个,但我自己处理过这个问题)。
child: TextField(
decoration: InputDecoration(
labelText: "em Dólares",
labelStyle: TextStyle(color: Colors.amber[600],
fontStyle: FontStyle.italic, fontSize: 10),
border: OutlineInputBorder(),
fillColor: Colors.black12,
filled: true,
contentPadding: EdgeInsetsDirectional.only(top: 20.0, bottom: 20.0, start: 5.0, end: 5.0), //<-- weak solution
prefixText: "US\$"),
style: TextStyle(color: Colors.amber[600], fontSize: 20.0),
)
我想你可以修改你的
floatingLabelStyle
和floatingLabelAlignment
(而不是labelStyle
):
TextField(
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
),
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'I am a very long text string yes I am',
prefixText: "US\$",
floatingLabelAlignment: FloatingLabelAlignment.start,
floatingLabelStyle: TextStyle(
color: Colors.green,
fontSize: 16,
),
),
),