我试过下面的代码,但它不会仅在按下时改变按钮的颜色。
//class attribute
Color bgColor = Colors.deepPurpleAccent;
//Widget
CupertinoButton(
color: bgColor,
child: Text('LOGIN', style: TextStyle(fontFamily: 'Roboto',)),
borderRadius: const BorderRadius.all(Radius.circular(80.0)),
onPressed: () {
this.setState(() {
bgColor = Colors.black;
});
print(_emailValue);
print(_passwordValue);
Navigator.pushReplacementNamed(context, '/products');
},
),
最佳答案
如果您只想调整突出显示按钮颜色的不透明度,您可以更改 pressedOpacity
属性:
CupertinoButton(
pressedOpacity: 0.4,
...
默认的 pressedOpacity
值为 0.1
,该值非常低。我发现 0.4
对于原生 iOS 外观来说更自然。
关于flutter - 如何仅在调用 onPressed 时更改 CupertinoButton 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56740448/