prashant.fepale
prashant.fepale

Reputation: 577

fomat partial text of Text widget in flutter

My Text widget looks like Text("Last Active: some location area..").

I can change text style of complete text using style. but I just like to change Last active as a bold. Text("<b>Last Active</b> some location area name..")

If I go with Row for separate text it will work but render a problem of spacing.

What's the best solution for this. And to make it bold is the only requirement.

Thanks

Upvotes: 10

Views: 6734

Answers (3)

Elmar
Elmar

Reputation: 4397

Working solution in 2022:

RichText( text: TextSpan(text: 'Last Active: ', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black), children:          
<TextSpan>[
TextSpan(text: 'some location area...', style: DefaultTextStyle.of(context).style), 
], ), ),

Upvotes: 0

Robbie
Robbie

Reputation: 320

I had problems with Andrey Turkovsky solution, the text area would be blank. I did find a slightly alternative solution. (I did want to comment to Andreys, and maybe he might be able to explain the differences between the two, Id be interested)

  Text.rich(
    TextSpan(
      children: [
        TextSpan(
            text: 'Last Active',
            style: TextStyle(fontWeight: FontWeight.bold)),
        TextSpan(text: ' some location area name..')
      ],
    ),
  )

Upvotes: 13

Andrii Turkovskyi
Andrii Turkovskyi

Reputation: 29438

RichText is solution

RichText(text: TextSpan(children: [
      TextSpan(text: 'Last Active', style: TextStyle(fontWeight: FontWeight.bold)),
      TextSpan(text: ' some location area name..')
    ]))

Upvotes: 16

Related Questions