如何移除Flutter TextField组件Label Text的背景色
解决方法
你当前Label Text的红色背景来自labelStyle属性内TextStyle显式配置的backgroundColor: Colors.red,要彻底移除背景而非设置透明效果,直接删除该参数即可:
Widget searchButton() { return TextField( decoration: InputDecoration( labelText: "Arama", hintText: "Ara", // 直接删除backgroundColor参数,无需额外设置透明 labelStyle: TextStyle(color: Colors.yellow), hintStyle: Theme.of(context).textTheme.button, ), ); }
如果删除该参数后仍然存在背景色,说明全局主题默认给InputDecoration的labelStyle配置了背景色,此时可以显式将backgroundColor赋值为null,完全禁用背景层绘制:
labelStyle: TextStyle(color: Colors.yellow, backgroundColor: null),
TextStyle的backgroundColor属性不传值或赋值为null时,Flutter不会为对应文本生成任何背景绘制层,完全符合你彻底移除背景的需求。
内容的提问来源于stack exchange,提问作者emirşah erden
相关产品推荐
相关产品推荐

