[英]How to remove underline below TextField?
嘗試為您的 TextField 小部件提供 TextStyle。 您的 TextField 正在獲取您的默認主題的 TextStyle。
TextField(
autofocus: true,
style: TextStyle(color: Colors.white, fontSize: 30),
decoration: InputDecoration.collapsed(
hintText: "Search",
border: InputBorder.none,
),
maxLines: 1,
)
在 TextField 小部件源代碼中,它指出:
/// If null, defaults to the `subhead` text style from the current [Theme].
final TextStyle style;
您應該在decoration
屬性中使用TextDecoration.none
。
Text(
'your txt',
style: TextStyle( decoration: TextDecoration.none),
)
我懷疑這與預測文本有關。 當您按空格鍵結束正在輸入的單詞時,下划線消失; 當您開始輸入下一個單詞時,它們會再次出現。 按照這里的建議,嘗試設置TextInputType.visiblePassword; - 這對我有用。
如https://stackoverflow.com/a/57499189/445887 所述
這是 Android 鍵盤的輔助功能(如果在TextStyle
禁用它后仍然看到下划線)。
然后在鍵入 use 時輸入文本總是帶有下划線:
autocorrect: false,
enableSuggestions: false,
Provide the following code inside the TextField widget and change the color according to the background color of a TextField. If the background is white provide white color which will make the underline invisible.
style: TextStyle(
fontSize: 16,
letterSpacing: 1,
decoration: TextDecoration.none,
decorationStyle: TextDecorationStyle.dotted,
decorationColor: Colors.white),
風格:TextStyle(decorationThickness:0)
你必須添加一個“decoration:TextDecoration.none”,像這樣:
Text(
"Don't forget",
style: TextStyle(
decoration: TextDecoration.none
)
)
@Immortal Dude是對的,這不是文本字段的問題。 因為在文本字段中輸入后單擊其他地方時,下划線會自動從文本中刪除。
您只需要設置鍵盤類型:
keyboardType: TextInputType.visiblePassword,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.