我想更改浮动按钮的颜色,但是我无法找到一种方法来解决该问题?预先感谢。
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),
);
通过代码:
var isPressed = false;
.....
floatingActionButton: FloatingActionButton(
child: Icon(Icons.check),
backgroundColor: isPressed ? Colors.green : Colors.blue,
onPressed: () => setState(() => isPressed = !isPressed),
),