Reputation: 577
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
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
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
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