在此输入图像描述 https://i.stack.imgur.com/LpWw0.png
我有三个按钮,当我按一个按钮时,我不希望所有按钮都更改背景颜色,只有选定的一个可以,那么我该如何实现这一目标?
尝试以下代码希望对您有帮助:
Create ElevatedButton
Widget.
ElevatedButton(
child: Text('Elevated Button'),
onPressed: () {
print('Pressed');
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed))
return Colors.blue;
return Colors.green;
},
),
),
),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)