Flutter文本出现黄色下划线求助,已尝试MaterialApp包裹无效
问题排查:文本黄色下划线问题
黄色下划线是Flutter内置的拼写检查提示,你的代码里有两处可能触发该提示:
- RichText中的
"asdad"被识别为拼写错误 - TextField的hintText
"What s your name?"存在语法错误(缺少撇号,正确写法应为"What's your name?")
解决方案
1. 修正拼写/语法错误
把TextField的hintText改为正确写法:
const TextField( decoration: InputDecoration( hintText: 'What\'s your name?', border: OutlineInputBorder()), ),
如果"asdad"是测试文本无需修正,可单独关闭该文本的拼写检查:
TextSpan( text: "asdad", style: TextStyle(color: Colors.black.withOpacity(0.6)), spellCheck: false // 关闭单个文本的拼写检查 )
2. 关闭单个输入框的拼写检查
若需保留原hintText写法,可关闭TextField的拼写检查:
TextField( spellCheckConfiguration: SpellCheckConfiguration.disabled(), decoration: InputDecoration( hintText: 'What s your name?', border: OutlineInputBorder()), ),
3. 全局关闭拼写检查
在MaterialApp中配置全局禁用拼写检查:
MaterialApp( spellCheckConfiguration: SpellCheckConfiguration.disabled(), home: YourScreen(), )
内容的提问来源于stack exchange,提问作者Marian
相关产品推荐
相关产品推荐

