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
TextSpanorTextwidgets - โ Preserves original icon font family and package
- โ
Accepts optional
TextStylewith easy overrides - โ Prefix and postfix text support โ combine icon and surrounding text in one widget
- โ
Inline
Text.richsupport with extra layout controls - โ
Optional
iconSizeandiconColoroverrides for icon only - โ
Optional
semanticsLabelfor screen readers (accessibility) - โ
Support for
TextAlign,TextDirection,maxLines, andTextOverflowin.toText() - โ
iconToString()utility to get the raw character - โ 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,
);
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
xIconData to TextSpan conversionxIconData to Text widget conversionxPrefix and postfix support in text conversionxCustom font sizes & colors viaiconSizeandiconColorxAccessibility support withsemanticsLabelxLayout controls:TextAlign,TextDirection,maxLines,TextOverflowUtility methods for inline rich contentSupport for other custom font iconsDedicated preview playground for live testing
๐ 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!