简体   繁体   English

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

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

This is what I have:这就是我所拥有的:

在此处输入图像描述

This is what I want:这就是我要的:

在此处输入图像描述

I want to remove the space between label text and bottom line, how to do that?我想删除 label 文本和底线之间的空格,该怎么做?

在此处输入图像描述

With InputDecorationTheme you can style TextformField like you want.使用InputDecorationTheme ,您可以根据需要设置TextformField的样式。 Also the padding.还有填充物。

Check this out: https://api.flutter.dev/flutter/material/InputDecorationTheme-class.html看看这个: 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,
            ),
        ),
)

You should use contentPadding parameter inside TextField's decoration.For example:您应该在 TextField 的装饰中使用contentPadding参数。例如:

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

You can set content Padding as you like to achieve desired results.您可以根据需要设置内容填充以获得所需的结果。

Another useful prop in InputDecoration is alignLableWithHint . alignLableWithHint InputDecoration This will lower the starting position to the same level as the text/hint text.这会将起始 position 降低到与文本/提示文本相同的级别。

Normally the label sits higher, even with contentPadding set to 0通常 label 坐得更高,即使 contentPadding 设置为 0

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter- 减少 TextFormField 的 hintText 和 suffixIcon 之间的填充 - Flutter- Reduce padding between hintText and suffixIcon for TextFormField Flutter 如何在 TextFormField 中添加填充? - Flutter how to add padding in TextFormField? Flutter - TextFormfield 在 UI 中占用太多填充/额外空间/如何使 label 文本在活动/非活动时具有相同大小 - Flutter - TextFormfield is taking too much padding/extra space in UI/How to make label text the same size when it is active/inactive Flutter TextFormField验证错误文本填充 - Flutter TextFormField Validation Error Text Padding Flutter TextFormField 为错误文本添加填充 - Flutter TextFormField add padding to error text 在 Flutter 中,如何在 textformfield 中设置 label 文本的样式? - In Flutter, how do I style the label text in textformfield when in focus? 如何设置TextFormField的文本左边距(非标签) Flutter - How to set TextFormField‘s text‘s left margin(Not Label) Flutter 垂直底部对齐 TextFormField 中的文本 Flutter - Vertically bottom Align Text in TextFormField Flutter Flutter Textformfield 如何在 Textformfield 中居中文本 - Flutter Textformfield How to center text in a Textformfield 如何在 TextFormField 中的 label 文本和用户输入之间添加间隙? - how to add gap between label text and user input in TextFormField?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM