浮动操作按钮颤动的更改颜色

问题描述 投票:0回答:1

我想更改浮动按钮的颜色,但是我无法找到一种方法来解决该问题?预先感谢。

 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),
    );
flutter background-color floating-action-button
1个回答
0
投票

通过代码:

var isPressed = false;
.....
floatingActionButton: FloatingActionButton(
    child: Icon(Icons.check),
    backgroundColor: isPressed ? Colors.green : Colors.blue,
    onPressed: () => setState(() => isPressed = !isPressed),
  ),
© www.soinside.com 2019 - 2024. All rights reserved.