【问题标题】:How can I change the font size differently?如何以不同方式更改字体大小?
【发布时间】:2021-01-06 20:30:14
【问题描述】:

例如,我想让 'Hello world' 变成 'Hello (//bigger than world) world (//smaller than Hello)' 他们在一行中。

我该怎么做? 我可以通过 TextStyle() 在一个 Text() 小部件中以不同的方式赋予它们的字体大小吗?

【问题讨论】:

  • 查看答案

标签: android ios flutter dart


【解决方案1】:

您可以像这样使用RichText 小部件:

RichText(
  text: TextSpan(
    text: 'Hello ',
    style: DefaultTextStyle.of(context).style,
    children: <TextSpan>[
      TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
      TextSpan(text: ' world!'),
    ],
  ),
)

【讨论】:

    【解决方案2】:

    请根据需要检查以下代码。

      RichText(
          text: TextSpan(
            text: 'Hello ',
            style: TextStyle(fontSize: 24),
            children: <TextSpan>[
              TextSpan(
                text: 'world!',
                style: TextStyle(fontSize: 18),
              ),
            ],
          ),
        )
    

    【讨论】:

      猜你喜欢
      • 2015-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多