Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add image to RichText element

I am trying to achieve following:

enter image description here

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.

like image 412
Code Hunter Avatar asked Jun 04 '26 04:06

Code Hunter


1 Answers

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",
      ),
    ],
  ),
),
like image 162
Ovidiu Avatar answered Jun 06 '26 18:06

Ovidiu