0

I want to change Color of my floating button when i hit that button but couldn't find out a way to do that, how can i solve it? thanks in advance.

 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),
    );

1 Answer 1

2

Go through the code:

var isPressed = false;
.....
floatingActionButton: FloatingActionButton(
    child: Icon(Icons.check),
    backgroundColor: isPressed ? Colors.green : Colors.blue,
    onPressed: () => setState(() => isPressed = !isPressed),
  ),
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.