簡體   English   中英

如何調整 Flutter TextField 高度?

[英]How to adjust Flutter TextField height?

我正在用 Flutter 構建一個社交網絡應用程序,所有的 TextField 都非常高。 我試過調整contentPadding參數,但它不起作用。 當我刪除inputDecorationinputDecoration其設置為null )時,問題就消失了,但在這種情況下,我無法顯示任何提示文本。

我還嘗試將 TextField 包裝在 Container 中並設置 Container 的高度,但這也無濟於事。 它只是扭曲了整個 TextField。

帶有擴展 TextField 的應用程序屏幕截圖

在此處輸入圖片說明

使用這兩行來控制InputDecoration TextFormField Height。

isDense: true, 
contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),

完整示例

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)),
                  ),
                ),
              ),

嘗試這個 ! 這將略有下降!

               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),
                    ),

嘗試這個:

TextField(
    decoration: InputDecoration(
        isDense: true,
        contentPadding: EdgeInsets.zero,
        border: InputBorder.none,
        hintText: Strings.settingGoodsTitle
    )
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM