dart - 如何在段落中加粗(或格式化)一段文本?

我怎样才能有不同格式的文本行?

例如:

你好世界

最佳答案

您应该使用 RichText小部件。

RichText 小部件将接收 TextSpan也可以具有子 TextSpan 列表的小部件。

每个 TextSpan 小部件可以有不同的 TextStyle .

这里是要渲染的示例代码: 你好世界

var text = RichText(
  text: TextSpan(
    // Note: Styles for TextSpans must be explicitly defined.
    // Child text spans will inherit styles from parent
    style: const TextStyle(
      fontSize: 14.0,
      color: Colors.black,
    ),
    children: <TextSpan>[
      TextSpan(text: 'Hello'),
      TextSpan(text: 'World', style: const TextStyle(fontWeight: FontWeight.bold)),
    ],
  ),
);

https://stackoverflow.com/questions/41557139/

相关文章:

flutter - 如何在 flutter 中为文本加下划线

flutter - 更改项目名称

android-studio - 未找到 flutter 命令

flutter - 等待另一个flutter命令释放启动锁

flutter - 如何在 flutter 中使用进度指示器?

flutter - 在 Flutter 中延迟一段时间后如何运行代码?

flutter - 如何在 Flutter 中以编程方式显示/隐藏小部件

dart - 具有透明背景的 flutter 角半径

android - 如何使用 Flutter 更改应用显示名称构建?

dart - Flutter 移除所有路由