![](/img/trans.png)
[英]flutter how remove text underline on text selection (TextFormField)?
[英]How to remove underline of input text in the TextFormField?
我想删除您在文本下方看到的黑色下划线。 每当我输入任何字符并添加每个字符时,它都会出现。 我怎样才能做到这一点? 这是我的 TextFieldForm 代码:
TextFormField(
controller: _controller,
showCursor: false,
toolbarOptions: ToolbarOptions(
cut: true,
copy: false,
selectAll: true,
paste: true,
),
decoration: InputDecoration(
border: InputBorder.none,
filled: true,
fillColor: Colors.white,
hintStyle: TextStyle(fontSize: 20),
hintText: "Search the word",
contentPadding: EdgeInsets.only(left: 20),
enabledBorder: OutlineInputBorder(borderSide: BorderSide.none),
suffixIcon:
Icon(Icons.search, color: Colors.black.withOpacity(0.6)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide.none,
),
),
),
我试过“边界:InputBorder.none”但失败了......
使用这个 function:
focusedBorder: InputBorder.none,
您可以覆盖 TextField 小部件中的inputFormatters ,并将自定义格式化程序 class 放置在数组中,如下面的片段。
我的自定义格式化程序 class:
class CaseFormatting extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
return TextEditingValue(
text: newValue.text,
selection: newValue.selection
);
}
}
并在 TextField 的 inputFormatters 中添加 class。
TextField(
//...
inputFormatters: [
CaseFormatting(),
// FilteringTextInputFormatter.allow(RegExp(r"[A-Z0-9]+")),
],
//...
)
style: TextStyle(
decoration: TextDecoration.none,
decorationThickness: 0,
),
我认为你必须在这样的装饰下添加focusBorder
:
decoration: InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.