TextButton(
child: Text(
'男',
style: TextStyle(
fontSize: 18,
color: Color.fromRGBO(255, 255, 255, 1)),
),
style: ButtonStyle(
//设置按钮大小
minimumSize: MaterialStateProperty.all(
const Size(90, 35)),
visualDensity: VisualDensity.compact,
overlayColor: MaterialStateProperty.all(
Colors.transparent),
//更优美的方式来设置
foregroundColor:
MaterialStateProperty.resolveWith(
(states) {
if (states
.contains(MaterialState.pressed)) {
//按下时的颜色
return Colors.blue;
}
//默认状态使用灰色
return Colors.black54;
},
),
//背景颜色
backgroundColor:
MaterialStateProperty.resolveWith(
(states) {
//设置按下时的背景颜色
if (states
.contains(MaterialState.pressed)) {
return Colors.blue;
}
//默认不使用背景颜色
return Colors.black12;
}),
),
onPressed: () {
},
flutter TextButton实现点击按钮变色效果
最新推荐文章于 2024-04-17 16:12:04 发布