文本我们一般使用Text widget,例如:
Text("HelloWorld",
style: TextStyle(
fontSize: 14.0,
color: Colors.black,
));
当需要将 HelloWorld 加粗改变颜色时,可以改写成富文本widget RichText
,利用 TextSpan
进行拼接,写法如下:
RichText(
text: TextSpan(
// 注意:TextSpan需要指定样式
// TextSpan子组件会继承父组件的样式
style: TextStyle(
fontSize: 14.0, //设置大小
color: Colors.red,//设置颜色
),
children: <TextSpan>[
TextSpan(text: "Hello"),
TextSpan(text: "World", style: new TextStyle(fontWeight: FontWeight.bold)),//其他样式设置粗体
],
),
);