How to change the background color of ElevatedButton in Flutter?

Issue

I tried to change the background color of ElevatedButton but it gave me an error. How can I change it?

ElevatedButton(
  onPressed: null,
  style: ButtonStyle(backgroundColor: Colors.red), // Error
}

Solution

Try This way

   ElevatedButton(            
            onPressed: () {},
            style: ElevatedButton.styleFrom(
                primary: Colors.red,
                ),)

Answered By – xahid_rocks

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *