flutter中修改一段文本中部分字体的样式

文本我们一般使用Text widget,例如:
Container(
child: Text(
"今年是2020年",
style: TextStyle(
fontSize: fitFont(14),
color: Color.fromRGBO(71, 75, 82, 1)),
)),
当我们想将 2020 加粗改变颜色时,可以改写成富文本widget RichText
,利用 TextSpan
进行拼接,写法如下:
Container(
child: RichText(
text: TextSpan(
style: TextStyle(
fontSize: fitFont(14),
color:
Color.fromRGBO(71, 75, 82, 1)),
children: [
TextSpan(text: '今年是'),
TextSpan(
text: '2020',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red)),
TextSpan(text: '年'),
]),
))
版权声明:
作者:东明兄
链接:https://blog.crazyming.com/note/2385/
来源:CrazyMing
文章版权归作者所有,未经允许请勿转载。


共有 0 条评论