Saad Mansoor
Saad Mansoor

Reputation: 365

How can I change the background and text color of a textbutton in flutter, in a single line?

most Easy Way to add a BackGroundColor to Textbutton

TextButton(
    style: TextButton.styleFrom(
            backgroundColor: Colors.red),
),

BUT, I also want to change text color:

TextButton(
    style: TextButton.styleFrom(
            textColor: Colors.white, 
            backgroundColor: Colors.red),
),

Upvotes: 1

Views: 150

Answers (1)

eamirho3ein
eamirho3ein

Reputation: 17880

You don't need to change textColor with TextButton Style. you can do that with child widget like this:

 TextButton(
      style: TextButton.styleFrom(
        backgroundColor: Colors.yellow,
      ),
      onPressed: () {},
      child: Text(
        'click',
        style: TextStyle(
          color: Colors.red,
        ),
      ),
    ),

enter image description here

Upvotes: 3

Related Questions