尝试为您的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; - 这对我有效。
样式:文本样式( 装饰厚度:0)
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),
当输入文本时,始终使用下划线:
autocorrect: false,
enableSuggestions: false,
如https://dev59.com/nrXna4cB1Zd3GeqPPbfp#57499189所述
这是一个无障碍功能(如果在TextStyle
中禁用后仍然看到下划线),来自Android键盘。
@Immortal Dude说得没错,这不是文本字段的问题。因为当您在文本字段中键入文本后单击其他地方时,下划线会自动从文本中移除。
您只需要设置键盘类型即可:
keyboardType: TextInputType.visiblePassword,
您需要添加“decoration: TextDecoration.none”,就像这样:
Text(
"Don't forget",
style: TextStyle(
decoration: TextDecoration.none
)
)
TextField(..., style: TextStyle(decoration: TextDecoration.none))
使用这个代码可以去除文本框中文字的下划线装饰。 - George Zvonov