'How to get the string content of text() widgets and give the styling below image shown in flutter

I want this type of output using single Text() widget

I am getting data from Api and i get gender from it so i just want to highlight that value by bold it on which gender i get from Api

example:enter image description here



Solution 1:[1]

You can wrap the Text() widget inside a Row() and provide separate styling.

return Row(
 children : [
  Text('Female'),
  Text('/'),
  Text('Male',
   style: TextStyle(
      fontWeight:FontWeight.bold, 
    ),
   ),
  ],
);
  

Solution 2:[2]

Try below code use RichText

RichText(
  text: TextSpan(
    text: 'Female',
    style: DefaultTextStyle.of(context).style,
    children: const <TextSpan>[
      TextSpan(
        text: '/',
      ),
      TextSpan(
        text: 'Male',
        style: TextStyle(
          fontWeight: FontWeight.bold,
        ),
      ),
    ],
  ),
),

Result Screen->image

Solution 3:[3]

RichText(
    text: TextSpan(
        text: "Female/",
        children: [
            TextSpan(text: "Male",style: TextStyle(fontWeight: FontWeight.bold))
        ]
    ),
),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arijeet
Solution 2 Ravindra S. Patil
Solution 3 Tyler2P