如何减少 Flutter 中 TextformField 中标签文本和底线之间的填充?

How to reduce padding between label text and bottom line in TextformField in Flutter?

这是我的:

这就是我想要的:

我想去掉标签文本和底线之间的space,怎么办?

使用 InputDecorationTheme,您可以随意设置 TextformField 的样式。还有填充。

看看这个: https://api.flutter.dev/flutter/material/InputDecorationTheme-class.html

MaterialApp(
        theme: ThemeData(
          inputDecorationTheme: InputDecorationTheme(
            border: OutlineInputBorder(),
            contentPadding: EdgeInsets.symmetric(
              vertical: 22,
              horizontal: 26,
            ),
            labelStyle: TextStyle(
              fontSize: 35,
              decorationColor: Colors.red,
            ),
        ),
)

您应该在 TextField 的 decoration.For 示例中使用 contentPadding 参数:

    TextField(
        decoration:InputDecoration(
          hintText:"LABEL",
          contentPadding: EdgeInsets.only(top:0.0,bottom:0.0)
        ),
       ),

您可以根据需要设置内容的Padding,以达到您想要的效果。

InputDecoration 中另一个有用的道具是 alignLableWithHint。这会将起始位置降低到与 text/hint 文本相同的级别。

通常情况下,标签位置较高,即使 contentPadding 设置为 0

    TextField(
       decoration:InputDecoration(
         hintText:"some label",
         alignLabelWithHint: true,
       ),
     ),