String to Icon ๐ŸŽฏ

GitLab

A Flutter package that maps string names to Material Icons IconData. Perfect for dynamic icon assignment from APIs, configuration files, or user input.

Features โœจ

  • ๐Ÿ” Case-insensitive mapping - "home", "HOME", "Home" all work
  • ๐Ÿš€ Space handling - "home work" maps to Icons.home_work
  • ๐Ÿ›ก๏ธ Fallback support - Unknown icons return Icons.circle
  • ๐Ÿ“ฆ 60+ Material Icons included out of the box
  • ๐Ÿงช Fully tested with comprehensive test coverage
  • ๐Ÿ“š Well documented with examples and API docs

Installation ๐Ÿ“ฆ

Add this to your package's pubspec.yaml file:

dependencies: string_to_icon: ^1.0.0

Then run:

flutter pub get

Quick Start ๐Ÿš€

import 'package:string_to_icon/string_to_icon.dart';

class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: [
Icon(IconMapper.getIconData('home')), // Icons.home
Icon(IconMapper.getIconData('map')), // Icons.map
Icon(IconMapper.getIconData('settings')), // Icons.settings
Icon(IconMapper.getIconData('unknown')), // Icons.circle (fallback)
],
);
}
}

Usage Examples ๐Ÿ’ก

Basic Icon Mapping

// Simple mapping IconData homeIcon = IconMapper.getIconData('home'); IconData mapIcon = IconMapper.getIconData('map'); IconData settingsIcon = IconMapper.getIconData('settings');

Case Insensitive

// All of these return Icons.home IconMapper.getIconData('home'); IconMapper.getIconData('HOME'); IconMapper.getIconData('Home'); IconMapper.getIconData('HoMe');

Space Handling

// Spaces are automatically handled IconMapper.getIconData('home work'); // Icons.home_work IconMapper.getIconData('maps home work'); // Icons.maps_home_work IconMapper.getIconData('battery charging'); // Icons.battery_charging_full

Dynamic Usage

final List<String> iconNames = ['home', 'map', 'settings', 'notifications'];

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: iconNames.length,
itemBuilder: (context, index) {
return ListTile(
leading: Icon(IconMapper.getIconData(iconNames[index])),
title: Text(iconNames[index]),
);
},
);
}
}

API Response Integration

final String name;
final String iconName;

MenuItem({required this.name, required this.iconName});
}

// From API response
Widget buildMenuItem(MenuItem item) {
return ListTile(
leading: Icon(IconMapper.getIconData(item.iconName)),
title: Text(item.name),
);
}

Available Icons ๐ŸŽจ

The package includes 60+ Material Icons covering common use cases:

Navigation & Location

  • home, map, directions, route, navigation

Device & System

  • devices, phone android, tablet android, wifi, bluetooth

Battery & Power

  • battery charging, battery4bar, battery1bar, power

People & Admin

  • person, people, admin panel settings, settings

Analytics & Charts

  • analytics, bar chart, show chart, data usage

Notifications & Alerts

  • notifications, alarm, warning, report

And many more! See the full list below.

Utility Methods ๐Ÿ› ๏ธ

// Check if an icon is supported bool isSupported = IconMapper.isSupported('home'); // true

// Get all supported icon names List

// Get total count int count = IconMapper.getSupportedIconCount(); // 60+

Fallback Behavior ๐Ÿ›ก๏ธ

When an unknown icon name is provided, the package returns Icons.circle as a safe fallback:

IconMapper.getIconData('unknown_icon'); // Returns Icons.circle IconMapper.getIconData(''); // Returns Icons.circle IconMapper.getIconData('nonexistent'); // Returns Icons.circle

Supported Icons ๐Ÿ“‹

Click to expand full icon list

Device Icons

  • tableandroid โ†’ Icons.tablet_android
  • devicehub โ†’ Icons.device_hub
  • tv โ†’ Icons.tv
  • devicesother โ†’ Icons.devices_other
  • devices โ†’ Icons.devices
  • phoneandroid โ†’ Icons.phone_android
  • route โ†’ Icons.route
  • directions โ†’ Icons.directions
  • map โ†’ Icons.map
  • mapshomework โ†’ Icons.maps_home_work
  • home โ†’ Icons.home
  • homework โ†’ Icons.home_work
  • locationpin โ†’ Icons.location_pin
  • navigation โ†’ Icons.navigation
  • mappointer โ†’ Icons.place

System & Settings

  • apps โ†’ Icons.apps
  • settings โ†’ Icons.settings
  • appsettingsalt โ†’ Icons.app_settings_alt
  • displaysettings โ†’ Icons.display_settings
  • engineering โ†’ Icons.engineering
  • darkmode โ†’ Icons.dark_mode

Connectivity

  • wifi โ†’ Icons.wifi
  • bluetooth โ†’ Icons.bluetooth
  • bluetoothsearching โ†’ Icons.bluetooth_searching
  • celltower โ†’ Icons.cell_tower
  • signalcellularalt โ†’ Icons.signal_cellular_alt

Battery & Power

  • batterystd โ†’ Icons.battery_std
  • batterycharging โ†’ Icons.battery_charging_full
  • battery4bar โ†’ Icons.battery_full
  • battery1bar โ†’ Icons.battery_1_bar
  • battery0bar โ†’ Icons.battery_0_bar
  • power โ†’ Icons.power

Analytics & Charts

  • barchart โ†’ Icons.bar_chart
  • analytics โ†’ Icons.analytics
  • datausage โ†’ Icons.data_usage
  • leaderboard โ†’ Icons.leaderboard
  • showchart โ†’ Icons.show_chart

People & Users

  • person โ†’ Icons.person
  • personoutline โ†’ Icons.person_outline
  • people โ†’ Icons.people
  • peopleoutline โ†’ Icons.people_outline
  • adminpanelsettings โ†’ Icons.admin_panel_settings

Authentication

  • login โ†’ Icons.login
  • logout โ†’ Icons.logout

Shapes & Design

  • formatshapes โ†’ Icons.format_shapes
  • shapeline โ†’ Icons.shape_line
  • hexagon โ†’ Icons.hexagon
  • category โ†’ Icons.category

Notifications & Alerts

  • alarm โ†’ Icons.alarm
  • alarmoff โ†’ Icons.alarm_off
  • notificationsnone โ†’ Icons.notifications_none
  • notificationsactive โ†’ Icons.notifications_active
  • notifications โ†’ Icons.notifications
  • warning โ†’ Icons.warning
  • dangerous โ†’ Icons.dangerous
  • warningamber โ†’ Icons.warning_amber_rounded
  • priorityhigh โ†’ Icons.priority_high
  • report โ†’ Icons.report
  • announcement โ†’ Icons.announcement
  • feedback โ†’ Icons.feedback

Weather & Time

  • sun โ†’ Icons.wb_sunny
  • moon โ†’ Icons.nightlight_round

Other

  • domain โ†’ Icons.domain
  • sensors โ†’ Icons.sensors
  • menu โ†’ Icons.menu
  • more โ†’ Icons.more_horiz

Example App ๐Ÿ“ฑ

The package includes a comprehensive example app that demonstrates:

  • Interactive icon lookup with text input
  • Grid view of all available icons
  • Popular icon examples as chips
  • Real-time feedback on icon support

To run the example:

cd example flutter run

Testing ๐Ÿงช

The package includes comprehensive tests covering:

  • โœ… Basic icon mapping
  • โœ… Case insensitive lookup
  • โœ… Space handling in names
  • โœ… Fallback behavior
  • โœ… Utility methods
  • โœ… Edge cases

Run tests with:

flutter test

Contributing ๐Ÿค

Contributions are welcome! If you'd like to add more icons or improve the package:

  1. Fork the repository
  2. Create a feature branch
  3. Add your changes with tests
  4. Submit a pull request

Adding New Icons

To add new icons, update the _iconMap in lib/src/icon_mapper.dart:

static final Map<String, IconData> _iconMap = { // ... existing icons 'newicon': Icons.new_icon, };

Don't forget to add tests for new icons!

License ๐Ÿ“„

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog ๐Ÿ“‹

See CHANGELOG.md for a list of changes in each version.


Made by team Combain with โค๏ธ for the Flutter Community

Libraries

string_to_icon
A Flutter package for mapping string names to Material Icons IconData.