gpt4 book ai didi

flutter - 如何仅在调用 onPressed 时更改 CupertinoButton 背景颜色

转载 作者:IT王子 更新时间:2023-10-29 06:56:31 25 4
gpt4 key购买 nike

我试过下面的代码,但它不会仅在按下时改变按钮的颜色。

//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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com