【发布时间】:2021-01-06 20:30:14
【问题描述】:
例如,我想让 'Hello world' 变成 'Hello (//bigger than world) world (//smaller than Hello)' 他们在一行中。
我该怎么做? 我可以通过 TextStyle() 在一个 Text() 小部件中以不同的方式赋予它们的字体大小吗?
【问题讨论】:
-
查看答案
例如,我想让 'Hello world' 变成 'Hello (//bigger than world) world (//smaller than Hello)' 他们在一行中。
我该怎么做? 我可以通过 TextStyle() 在一个 Text() 小部件中以不同的方式赋予它们的字体大小吗?
【问题讨论】:
您可以像这样使用RichText 小部件:
RichText(
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' world!'),
],
),
)
【讨论】:
请根据需要检查以下代码。
RichText(
text: TextSpan(
text: 'Hello ',
style: TextStyle(fontSize: 24),
children: <TextSpan>[
TextSpan(
text: 'world!',
style: TextStyle(fontSize: 18),
),
],
),
)
【讨论】: