Emir Kutlugün
Emir Kutlugün

Reputation: 447

Changing Color of Floating Action Button Flutter

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

Upvotes: 0

Views: 2530

Answers (1)

Sanket Vekariya
Sanket Vekariya

Reputation: 2956

Go through the code:

var isPressed = false;
.....
floatingActionButton: FloatingActionButton(
    child: Icon(Icons.check),
    backgroundColor: isPressed ? Colors.green : Colors.blue,
    onPressed: () => setState(() => isPressed = !isPressed),
  ),

Upvotes: 2

Related Questions