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

Time:10-25

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),
),

CodePudding user response:

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

  • Related