Jeremy West
Jeremy West

Reputation: 7

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!

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

Upvotes: 0

Views: 2039

Answers (1)

Air Admirer
Air Admirer

Reputation: 948

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

Upvotes: 1

Related Questions