如何调整 Flutter TextField 高度?

kri*_*han 4 mobile android ios flutter

我正在用 Flutter 构建一个社交网络应用程序,所有的 TextField 都非常高。我试过调整contentPadding参数但它不起作用。当我删除inputDecoration(即将其设置为null)时,问题就消失了,但在这种情况下,我无法显示任何提示文本。

我还尝试将 TextField 包装在 Container 中并设置 Container 的高度,但这也无济于事。它只是扭曲了整个 TextField。

带有扩展 TextField 的应用程序屏幕截图

Jew*_*ana 11

在此处输入图片说明

使用这两行来控制TextFormFieldHeight 里面InputDecoration

isDense: true, 
contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),
Run Code Online (Sandbox Code Playgroud)

完整示例

Material(
                elevation: 4,
                shadowColor: Colors.blue,
                shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                child: Padding(
                  padding: const EdgeInsets.only(left: 12),
                  child: TextFormField(
                    controller: searchProvider.searchController,
                    keyboardType: TextInputType.text,
                    decoration: InputDecoration(
                        hintText: 'hintText',
                        isDense: true, // important line
                        contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),// control your hints text size
                        hintStyle: TextStyle(letterSpacing: 2, color: Colors.black54, fontWeight: FontWeight.bold),
                        fillColor:  Colors.white30 ,
                        filled: true,
                        border: OutlineInputBorder(borderRadius: BorderRadius.circular(30), borderSide: BorderSide.none)),
                  ),
                ),
              ),
Run Code Online (Sandbox Code Playgroud)

  • 这!我将“TextFormField”放入“Container”中并更改了“contentPadding”。工作起来就像一个魅力。谢谢你! (2认同)

小智 8

尝试这个:

TextField(
    decoration: InputDecoration(
        isDense: true,
        contentPadding: EdgeInsets.zero,
        border: InputBorder.none,
        hintText: Strings.settingGoodsTitle
    )
)
Run Code Online (Sandbox Code Playgroud)


Nav*_*idi 5

尝试这个 !这将略有下降!

               TextField(
                      decoration: InputDecoration(
                        contentPadding:EdgeInsets.fromLTRB(10,0,10,0),
                        //The above line will help !
                        border: OutlineInputBorder(),
                        labelText: 'Name',
                        labelStyle:
                            TextStyle(color: Colors.white, fontSize: 17),
                      ),
                      style: TextStyle(color: Colors.white, fontSize: 17),
                    ),
Run Code Online (Sandbox Code Playgroud)