How to remove underline below TextField?

Rahul Lohra picture Rahul Lohra · May 26, 2019 · Viewed 11.2k times · Source

Here is the code. I want to remove the black underline just below text, and currently the TextField is in edit mode:

TextField(
      autofocus: true,
      decoration: InputDecoration.collapsed(
        hintText: "Search",
        border: InputBorder.none,
      ),
      maxLines: 1,
    )

Answer

Ali Türkay Avci picture Ali Türkay Avci · Jan 28, 2020

Try to give a TextStyle to your TextField widget. Your TextField is getting your default Theme's TextStyle.

TextField(
      autofocus: true,
      style: TextStyle(color: Colors.white, fontSize: 30),
      decoration: InputDecoration.collapsed(
        hintText: "Search",
        border: InputBorder.none,
      ),
      maxLines: 1,
    )

In TextField widgets source code it states:

  /// If null, defaults to the `subhead` text style from the current [Theme].
  final TextStyle style;