You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除或禁用TextField/TextFormField的文本自动高亮(子串模式不可预测)

移除TextField/TextFormField文本自动高亮的方法

以下是几种有效的解决方式,可根据实际情况组合使用:

  • 禁用拼写检查与输入建议:在TextField中添加autocorrect: false和enableSuggestions: false属性,关闭系统层面的拼写纠错和输入建议功能,从根源上避免相关的文本高亮。
  • 关闭自动填充:设置autofillHints: [],清空自动填充提示列表,防止自动填充触发的文本高亮。
  • 强制覆盖高亮样式:在文本样式style中设置backgroundColor: Colors.transparent(或与输入框背景色一致),直接覆盖可能存在的高亮背景色。

修改后的完整代码示例:

TextField(
  autocorrect: false,
  enableSuggestions: false,
  autofillHints: [],
  decoration: InputDecoration(
    hintText: 'search'.tr,
    hintStyle: TextStyle(
      color: Colors.grey,
      fontSize: 18,
      fontStyle: FontStyle.normal,
    ),
    border: InputBorder.none,
  ),
  style: TextStyle(
    color: AppThemes.primaryColorWine,
    backgroundColor: Colors.transparent,
  ),
),

如果使用TextFormField,同样可以添加上述属性来达到效果。

内容的提问来源于stack exchange,提问作者shortstopmin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 03:32:17