简体   繁体   English

如何删除 TextFormField 中输入文本的下划线?

[英]How to remove underline of input text in the TextFormField?

在此处输入图像描述

I want to remove the black underline that you see under the text.我想删除您在文本下方看到的黑色下划线。 It come whenever I input any character and addon with every character.每当我输入任何字符并添加每个字符时,它都会出现。 How can I achieve this?我怎样才能做到这一点? Here is my TextFieldForm code:这是我的 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,
            ),
          ),
        ),

I tried "border: InputBorder.none" but fail....我试过“边界:InputBorder.none”但失败了......

Use this function:使用这个 function:

focusedBorder: InputBorder.none,

I guess that's for the OS of your device.我想这是针对您设备的操作系统的。 It's an auto completion option.这是一个自动完成选项。 As you can see it removes the underline when you press Space (means the word has ended).正如您所看到的,当您按空格键时它会删除下划线(表示单词已结束)。 You have disable it in the phone settings and have nothing to do with your code.您已在手机设置中禁用它,与您的代码无关。 To do so try following:为此,请尝试以下操作:

  1. Open the Settings menu on your phone or tablet and select Languages & Input.打开手机或平板电脑上的设置菜单,然后打开 select 语言和输入法。

  2. Tap Virtual keyboard under Keyboard and input methods.点击键盘和输入法下的虚拟键盘。

  3. Select Android Keyboard. Select Android 键盘。

在此处输入图像描述

  1. Turn off the auto correction and show correction suggestions and also next word suggestion.关闭自动更正并显示更正建议以及下一个单词建议。

You can overrider the inputFormatters in the TextField Widget and place the custom formatter class in the array like the below snippets.您可以覆盖 TextField 小部件中的inputFormatters ,并将自定义格式化程序 class 放置在数组中,如下面的片段。

My Custom Formatter class:我的自定义格式化程序 class:

    class CaseFormatting extends TextInputFormatter {
  @override
  TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
    return TextEditingValue(
      text: newValue.text,
      selection: newValue.selection
    );
  }
}

And in the TextField add the class in the inputFormatters.并在 TextField 的 inputFormatters 中添加 class。

    TextField(
  //...
                inputFormatters: [
                  CaseFormatting(),
                  // FilteringTextInputFormatter.allow(RegExp(r"[A-Z0-9]+")),
                ],
  //...
              )
    style: TextStyle(
      decoration: TextDecoration.none,
      decorationThickness: 0,
    ),

I think you have to add focusBorder under the decoration like this:我认为你必须在这样的装饰下添加focusBorder

 decoration: InputDecoration(
                  border: InputBorder.none,
                  focusedBorder: InputBorder.none,
                ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM