在 TextField 小部件中输入文本时无法删除下划线

UTK*_*rma 2 dart flutter

在文本字段中输入文本时,有一条下划线一直存在,直到我正在打字为止,并且当我关闭我尝试过的键盘时,该下划线会消失:

 TextField(
                style: TextStyle(
                  decoration: TextDecoration.none,
                  color: Colors.white,
                ),
                cursorColor: Colors.grey.withOpacity(0.8),
                decoration: InputDecoration(
                  labelText: "email",
                  labelStyle: TextStyle(decoration: TextDecoration.none),
                  hintStyle: TextStyle(
                    color: Colors.grey,
                  ),
                  hintText: "email",
                  filled: true,
                  fillColor: Colors.grey.withOpacity(0.5),
                  prefixIcon: Icon(
                    Icons.alternate_email,
                    color: Colors.grey.withOpacity(0.8),
                  ),
                  enabledBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(100),
                    borderSide: BorderSide.none,
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(100),
                    borderSide: BorderSide.none,
                  ),
                ),
              ),
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Dar*_*han 9

这不是一个错误,而是 的默认行为TextField。您键入时文本的下划线与键盘相关,这意味着它充当拼写检查器,以便您可以确认您键入的内容是否正确。如果您仍然想在键入时隐藏下划线,则需要使用:

autoCorrect: falseenableSuggestions: false属性,并从设备/模拟器的设置中TextField手动关闭虚拟键盘的选项。text suggestion

当我执行上述操作时,示例工作代码如下:

child: TextField(
              enableSuggestions: false,
              autocorrect: false,
              style: TextStyle(
                decoration: TextDecoration.none,
                color: Colors.white,
              ),
              cursorColor: Colors.grey.withOpacity(0.8),
              decoration: InputDecoration(
                labelText: "email",
                labelStyle: TextStyle(decoration: TextDecoration.none),
                hintStyle: TextStyle(
                  color: Colors.grey,
                ),
                hintText: "email",
                filled: true,
                fillColor: Colors.grey.withOpacity(0.5),
                prefixIcon: Icon(
                  Icons.alternate_email,
                  color: Colors.grey.withOpacity(0.8),
                ),
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(100),
                  borderSide: BorderSide.none,
                ),
                focusedBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(100),
                  borderSide: BorderSide.none,
                ),
              ),
            ),
Run Code Online (Sandbox Code Playgroud)

然后我就可以输入没有下划线的内容了。

在此输入图像描述

希望这能回答您的问题。