0
votes

in flutter and my application i'm trying to change some FlatButton text colors without using ThemeData, because in some part of application i want to have button with white text color or red, how can i set this text colors normally?

for example:

FlatButton(
    color: Colors.black,
    textColor: Colors.white,
    child: Text(
      'login'
    ),
    onPressed: () {}
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0))),

FlatButton(
    color: Colors.yellow,
    textColor: Colors.red,
    child: Text(
      'login'
    ),
    onPressed: () {}
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0))),    

FlatButton(
    color: Colors.white,
    textColor: Colors.green,
    child: Text(
      'login'
    ),
    onPressed: () {}
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0))),    
2
"how can i set this text colors normally?" - you already did it: color: Colors.yellow, textColor: Colors.red, - pskink
@pskink yes, but it didn't work and all of button's textColors are black - DolDurma
FlatButton( onPressed: () {}, textColor: Colors.red, child: Text('foo', textScaleFactor: 3.0,), ), works just fine - pskink

2 Answers

4
votes

Try TextStyle using inside the Text widget like below :

FlatButton(
    color: Colors.yellow,
    child: Text(
      'login',style: TextStyle(color: Colors.red)
    ),
    onPressed: () {}
    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0))),  
1
votes

I don't know why the textColor property isn't working for you, but try giving the child text widget style as I have shown below it will work.

FlatButton(
      color: Colors.red,
      textColor: Colors.green,
      child: Text("This is a flatButton",
          style: TextStyle(
            color: Colors.white, //This will do the work
          )),
      onPressed: () {},
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0)),
    ),