简体   繁体   中英

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:

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....

Use this 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.

  2. Tap Virtual keyboard under Keyboard and input methods.

  3. Select Android Keyboard.

在此处输入图像描述

  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.

My Custom Formatter 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: [
                  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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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