【问题标题】:Add image to RichText element将图像添加到 RichText 元素
【发布时间】:2019-07-31 09:06:03
【问题描述】:

我正在努力实现以下目标:

为了实现这一点,我正在使用 RichText。使用它,我可以添加多个具有不同样式的文本。但我不知道如何将图像添加到这个 TextSpan。可能还有其他元素。

【问题讨论】:

    标签: flutter dart richtext


    【解决方案1】:

    您不需要第三方库来实现这一点。在最新的稳定版本中,Flutter 引入了WidgetSpan。这类似于TextSpan,但您可以使用任何小部件而不仅仅是文本。示例代码:

    RichText(
      text: TextSpan(
        children: [
          TextSpan(
            text: "Click ",
          ),
          WidgetSpan(
            child: Icon(Icons.add, size: 14),
          ),
          TextSpan(
            text: " to add",
          ),
        ],
      ),
    ),
    

    【讨论】:

    猜你喜欢
    • 2020-05-28
    • 2015-06-20
    • 2014-07-25
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2011-10-03
    相关资源
    最近更新 更多