如何在Flutter中用一行代码修改TextButton的背景色与文字颜色?
要快速调整TextButton的样式,官方推荐使用TextButton.styleFrom()方法,这是最简洁的配置方式:
仅修改背景色
在style参数中传入配置了backgroundColor的styleFrom()即可:
TextButton( style: TextButton.styleFrom(backgroundColor: Colors.red), onPressed: () {}, // 必填的点击回调 child: const Text("示例按钮"), ),
同时修改文字颜色与背景色
在styleFrom()中同时指定textColor和backgroundColor参数:
TextButton( style: TextButton.styleFrom( textColor: Colors.white, backgroundColor: Colors.red, ), onPressed: () {}, child: const Text("示例按钮"), ),
内容的提问来源于stack exchange,提问作者Saad Mansoor
相关产品推荐
相关产品推荐

