Search code examples
flutterdartuser-interfacematerial3

How to create perfectly white Elevated Button with Material3 with elevation?


I am working on an ElevatedButton style in Flutter and I try to make it perfectly white inside with some elevation, but I can't achieve it. Here is my style:

ButtonStyle(
elevation: MaterialStateProperty.all(5), 
backgroundColor: MaterialStateProperty.all(
    Colors.white), 
)

But when I try to actually use it the button isn't white, but a little bit darker.

enter image description here

Also when I try any other color with elevation the same thing happens and the colors aren't perfectly adequate.

I found out there is a thing called surfaceTintColor which seems to change the exact color of a button.


Solution

  • Result:

    enter image description here

    You can play around with the ButtonStyle/elevation:

     ElevatedButton(
                style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.all<Color>(Colors.white),
                  foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
                  overlayColor: MaterialStateProperty.all<Color>(Colors.white),
                  shadowColor: MaterialStateProperty.all<Color>(Colors.white),
                  elevation: MaterialStateProperty.all<double>(0.1),
                ),
                child: Text(
                  'Elevated Button',
                  style: TextStyle(color: Colors.black),
                ),
                onPressed: () {},
              )