如何在段落中加粗(或设置格式)一段文本? [英] How do I bold (or format) a piece of text within a paragraph?

查看:103
本文介绍了如何在段落中加粗(或设置格式)一段文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用不同的格式显示一行文本?

How can I have a line of text with different formatting?

例如:

您好世界

推荐答案

您应使用 RichText 小部件。

RichText小部件将采用 TextSpan 小部件,也可以具有子TextSpans子列表。

A RichText widget will take in a TextSpan widget that can also have a list of children TextSpans.

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

Each TextSpan widget can have a different TextStyle.

以下是要渲染的示例代码:
您好世界

Here is the example code to render: Hello World

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

这篇关于如何在段落中加粗(或设置格式)一段文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆