【问题标题】:How to increase the text field label size (width) in flutter?如何在颤动中增加文本字段标签大小(宽度)?
【发布时间】:2019-07-24 13:22:15
【问题描述】:

有什么方法可以在颤动中增加文本字段标签的宽度,以避免省略号(...)?

标签总是小于文本字段区域。

我能想到的改进方法就是减少内容填充的“开始”和“结束”,但效果微乎其微。

                  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。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    要更改(减少/增加)标签的字体大小,您可以使用TextStyle() 中的fontSize: 属性。只需将字体大小添加到标签即可。

    【讨论】:

    • 是的,我已经使用过。问题不在于字体大小,而在于字段标签大小。谢谢。
    • 您可以在容器内使用TextField 并为容器设置高度和宽度
    【解决方案2】:

    使用labelStyle 中的fontSize 属性缩小标签文本的字体大小。如果标签的文本超过文本字段大小的一半左右,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),
                      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-10
      • 2017-07-27
      • 2011-03-19
      • 2020-12-31
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多