Search code examples
flutterdartflutter-layout

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

Solution

  • 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