How to remove underline below TextField?

百般思念 提交于 2020-05-14 18:05:48

问题


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,
    )


回答1:


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;



回答2:


You have to add a "decoration:TextDecoration.none", like this:

  Text(
    "Don't forget",
    style: TextStyle(
       decoration: TextDecoration.none
    )
  )



回答3:


You should use TextDecoration.none in decoration property.

Text(
  'your txt',
  style: TextStyle( decoration: TextDecoration.none),
)



回答4:


@Immortal Dude is right that this is not the problem of textfield. Because when you click somewhere else after typing in the textfield, the underline automatically remove from the text.

You just need to set the keyboard type:

keyboardType: TextInputType.visiblePassword,


来源:https://stackoverflow.com/questions/56315495/how-to-remove-underline-below-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!