将图像添加到RichText元素 [英] Add image to RichText element

查看:53
本文介绍了将图像添加到RichText元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to achieve following:

为此,我正在使用RichText.使用此功能,我可以添加具有不同样式的多个文本.但是我不知道如何将图像添加到此TextSpan中.可能还有其他因素.

To achieve this I am using RichText. Using this I can add multiple text with different styles. But I am not getting idea how I can add image to this TextSpan. May be there is some other element.

推荐答案

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

You do not need third-party libraries to achieve this. With the latest stable release, Flutter has introduced WidgetSpan. This is similar to TextSpan but you can use any widget instead of just text. Sample code:

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

这篇关于将图像添加到RichText元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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