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

How can I add color to a button in Flutter?

I tried to add color to my FlatButton in Flutter but I get an error as below:
The named parameter ‘color’ isn’t defined.
Try correcting the name to an existing named parameter’s name, or defining a named parameter with the name

my codeenter image description here

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

>Solution :

You want to use FlatButton but you are calling FloatingActionButton. that is your first issue.

You can use backgroundColor to change the background color of FloatingActionButton, like this:

FloatingActionButton(
            onPressed: () {},
            backgroundColor: Colors.red,
            child: Text('click'),
          ),

enter image description here

But I notice that you mention FlatButton in your description. FlatButton is deprecated and shouldn’t be used, instead use TextButton, like this:

TextButton(
            onPressed: () {},
            style: ButtonStyle(
                backgroundColor: MaterialStateProperty.all(Colors.red)),
            child: Text('click'),
          ),

enter image description here

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