![](/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.