Banner

icondata_to_text_extension

Pub Version GitHub License

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 or Text 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 and iconColor overrides for icon only
  • βœ… Optional semanticsLabel for screen readers (accessibility)
  • βœ… Support for TextAlign, TextDirection, maxLines, and TextOverflow 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 and iconColor
  • βœ… 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

Example Example

πŸ’‘ Roadmap

  • x IconData to TextSpan conversion
  • x IconData to Text widget conversion
  • x Prefix and postfix support in text conversion
  • x Custom font sizes & colors via iconSize and iconColor
  • x Accessibility support with semanticsLabel
  • x Layout controls: TextAlign, TextDirection, maxLines, TextOverflow
  • Utility methods for inline rich content
  • Support for other custom font icons
  • Dedicated 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!