如何移除或禁用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
相关产品推荐
相关产品推荐

