切换 .resume 和 .pause 时更改订阅图标按钮的颜色。为什么这不起作用?


IconButton(
icon: Icon(MdiIcons.moonWaxingCrescent),
onPressed: () {
expanded ? subscription.resume() : subscription.pause();

setState(() {
expanded
? Color(0xffF2E03F)
: Color(0xffFFFFFF);
expanded = !expanded;
});
}),

上面的代码不会改变我的颜色,但确实正确地执行了函数(切换恢复和暂停(。我试着把它从我使用的动画图标改过来,但我想这与订阅有点不同。这是我不需要的工作动画图标:

IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow,
progress: _animationController,
semanticLabel: 'Pause',
),
onPressed: () {
expanded ? subscription.resume() : subscription.pause();
setState(() {
expanded
? _animationController.forward()
: _animationController.reverse();
expanded = !expanded;
});
}),

知道如何让第一个按钮根据.继续和.暂停状态改变颜色吗?

明白了!

IconButton(
icon: Icon(MdiIcons.moonWaxingCrescent),
color: (expanded) ? Color(0xffFF0000) : Color(0xff000000),
onPressed: () {
expanded ? subscription.resume() : subscription.pause();
setState(() {
expanded = !expanded;
});
}),

最新更新