Home > database >  How can I add color to a button in Flutter?
How can I add color to a button in Flutter?

Time:09-09

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

CodePudding user response:

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

  • Related