
icondata_to_text_extension
Convert any Flutter IconData
(Material or Cupertino) into inline Text
or TextSpan
widgets with correct font rendering.
Ideal for rich text, custom layouts, or displaying icons as text in Flutter apps.
β¨ Fully null-safe, simple, customizable, and accessible.
π Features
- β Supports both Material and Cupertino icons
- β
Converts IconData to
TextSpan
orText
widgets - β Optional onTap callback for interactive text
- β Preserves original icon font family and package
- β
Accepts optional
TextStyle
with easy overrides - β Prefix and postfix text support β combine icon and surrounding text in one widget
- β
Inline
Text.rich
support with extra layout controls - β
Optional
iconSize
andiconColor
overrides for icon only - β
Optional
semanticsLabel
for screen readers (accessibility) - β
Support for
TextAlign
,TextDirection
,maxLines
, andTextOverflow
in.toText()
- β
iconToString()
utility to get the raw character - β Utility widget IconTextLabel for declarative usage
- β Minimal, zero-dependency extension
π§ Installation
Add to your pubspec.yaml
:
dependencies:
icon_to_text_extension_codespark: ^0.0.2
Then run:
flutter pub get
π§ͺ Usage
Convert IconData to TextSpan
final span = CupertinoIcons.share.toTextSpan(
style: TextStyle(fontSize: 24, color: Colors.blue),
);
Convert IconData to Text widget
final widget = Icons.share.toText(
style: TextStyle(fontSize: 30, color: Colors.green),
textAlign: TextAlign.center,
);
Got it! Here's the updated Roadmap section replacing the "Use in RichText" example with a usage example of the new IconTextLabel
widget:
π‘ Roadmap
- β IconData to TextSpan conversion
- β IconData to Text widget conversion
- β Prefix and postfix support in text conversion
- β
Custom font sizes & colors via
iconSize
andiconColor
- β
Accessibility support with
semanticsLabel
- β
Layout controls:
TextAlign
,TextDirection
,maxLines
,TextOverflow
- β
Utility widget
IconTextLabel
for declarative usage - π Utility methods for inline rich content
- π Support for other custom font icons
- π Dedicated preview playground for live testing
π§± Use with IconTextLabel
IconTextLabel(
icon: Icons.send,
prefix: 'Send ',
postfix: ' Now',
iconSize: 20,
textStyle: TextStyle(fontSize: 16),
)
Use prefix and postfix to reduce extra spans/widgets
final spanWithText = CupertinoIcons.share.toTextSpan(
prefix: 'Tap ',
postfix: ' to share',
style: TextStyle(fontSize: 24, color: Colors.black),
);
final textWithIcon = Icons.share.toText(
prefix: 'Click ',
postfix: ' here',
style: TextStyle(fontSize: 28, color: Colors.purple),
);
Use in RichText
RichText(
text: TextSpan(
children: [
TextSpan(text: 'Click the '),
CupertinoIcons.share.toTextSpan(style: TextStyle(color: Colors.black)),
TextSpan(text: ' button to share.'),
],
),
)
Override icon size and color
Icons.star.toText(
iconSize: 32,
iconColor: Colors.amber,
);
Add semantics label for accessibility
CupertinoIcons.share.toText(
semanticsLabel: 'Share icon',
);
π· Preview


π‘ Roadmap
x
IconData to TextSpan conversionx
IconData to Text widget conversionx
Prefix and postfix support in text conversionx
Custom font sizes & colors viaiconSize
andiconColor
x
Accessibility support withsemanticsLabel
x
Layout controls:TextAlign
,TextDirection
,maxLines
,TextOverflow
π Example
Clone or open the example/
folder and run:
flutter run
π Check Out My Other Packages!
Explore more Flutter packages by Katayath Sai Kiran to add unique UI effects and functionality to your apps.
π¨βπ» Maintainer
Developed with π by Katayath Sai Kiran π¬ Contributions and suggestions are always welcome!