簡體   English   中英

如何刪除 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,

我想這是針對您設備的操作系統的。 這是一個自動完成選項。 正如您所看到的,當您按空格鍵時它會刪除下划線(表示單詞已結束)。 您已在手機設置中禁用它,與您的代碼無關。 為此,請嘗試以下操作:

  1. 打開手機或平板電腦上的設置菜單,然后打開 select 語言和輸入法。

  2. 點擊鍵盤和輸入法下的虛擬鍵盤。

  3. Select Android 鍵盤。

在此處輸入圖像描述

  1. 關閉自動更正並顯示更正建議以及下一個單詞建議。

您可以覆蓋 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.

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