Flutter – How to add an Icon in a Text

In this post, I will show you how to add an Icon (or any other widget) in a Text.

To do that we will need to combine RichText or Text.rich and WidgetSpan:

Text.rich(
    TextSpan(
        children: <InlineSpan>[
            TextSpan(text: 'Our application already has'),
            WidgetSpan(
                alignment: ui.PlaceholderAlignment.middle,
                child: Icon(Icons.ten_k, color: Colors.red, size: 60,)),
            TextSpan(text: 'downloads on both stores'),
        ],
      ),
      textAlign: TextAlign.center,
      style: TextStyle(
        fontSize: 40
      ),
)
Tagged : / / /
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Jonh
Jonh
1 month ago

Great

1
0
Would love your thoughts, please comment.x
()
x