skip to Main Content

I am defining a string and now I want to set my string a color, please show how do I do that with my code

  final String followOnLabel = inningScore.followOn! ? ' (f/o)' : '';

I want to set my string followOnLabel color or textstyle. Thank you in advance.

2

Answers


  1. Strings are text. They don’t have colors. Widgets have colors. To give a Text widget a red text you could write this for example:

    Text(followOnLabel , style: const TextStyle(color: Colors.red))
    
    Login or Signup to reply.
  2. @SaDev As I understand, do you want to change the colour of your string depending on the condition? If yes then the below code will help you to meet your requirements.

    Text(
     followOnLabel,
     style: TextStyle(
         fontFamily: /*Font Family*/,
         color: inningScore.followOn! ? Colors.yellow : Colors.red)
    )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search