Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't set primary colour of ElevatedButton in Flutter

I have an elevated button in Flutter, generally the button works fine.

However, the setting of the primary: Colors.red in this example does not work, the button is transparent for some reason… All the other params of the ElevatedButton.styleFrom() are working as expected.

Any assistance would be appreciated!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Widget _btnGood() {
    return SizedBox(
      width: MediaQuery.of(context).size.width * 0.8,
      child: ElevatedButton(
        onPressed: null,
        style: ElevatedButton.styleFrom(
          primary: Colors.purple,
          side: const BorderSide(width: 8.0, color: Colors.white),
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(32)),
          padding: const EdgeInsets.all(25),
        ),
        child: const Text(
          "Im Feeling Good",
          style: TextStyle(
            color: Colors.white,
            fontSize: 30,
          ),
        ),
      ),
    );
  }

Example of Button

>Solution :

Simply change on pressed to-
on_pressed: (){} instead of null.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading