我想在我按下浮动按钮时更改其颜色,但找不到解决方法,我该如何解决?预先感谢。
var color1;
var floatingActionButton1 = FloatingActionButton(
onPressed: () {
setState(() {
simpleInterest.principal = double.parse(_principalController.text);
color1 = Colors.green;
});
},
elevation: 40,
backgroundColor: color1,
heroTag: "btn1",
child: Icon(Icons.check),
);
答案 0 :(得分:1)
浏览代码:
var isPressed = false;
.....
floatingActionButton: FloatingActionButton(
child: Icon(Icons.check),
backgroundColor: isPressed ? Colors.green : Colors.blue,
onPressed: () => setState(() => isPressed = !isPressed),
),