在下面的代码中,我想将“$_counter”的值设为粗体。如何实现?
new Text(
'You have pushed the button $_counter time${_counter > 1
? 's'
: ''}',
style: new TextStyle(fontSize: fontSize),
textAlign: TextAlign.center,
),
我希望输出是这样的:
您已按下按钮 2 次
最佳答案
你必须使用 RichTextfor
new RichText(
textAlign: TextAlign.center,
text: new TextSpan(
style: TextStyle(color: Colors.black),
children: <TextSpan>[
new TextSpan(text: 'You have pushed the button '),
new TextSpan(text: '$_counter', style: new TextStyle(fontWeight: FontWeight.bold)),
new TextSpan(text: ' time!'),
],
),
)
关于android-studio - 我如何格式化(粗体)文本中的单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51319174/