Home > OS >  Can't set primary colour of ElevatedButton in Flutter
Can't set primary colour of ElevatedButton in Flutter

Time:02-01

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

CodePudding user response:

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

  •  Tags:  
  • Related