string_to_icon 1.0.0
A Flutter package that converts string icon names to IconData objects from the Material Icons set.
String to Icon 🎯
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 toIcons.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_androiddevicehub→ Icons.device_hubtv→ Icons.tvdevicesother→ Icons.devices_otherdevices→ Icons.devicesphoneandroid→ Icons.phone_android
Navigation & Location
route→ Icons.routedirections→ Icons.directionsmap→ Icons.mapmapshomework→ Icons.maps_home_workhome→ Icons.homehomework→ Icons.home_worklocationpin→ Icons.location_pinnavigation→ Icons.navigationmappointer→ Icons.place
System & Settings
apps→ Icons.appssettings→ Icons.settingsappsettingsalt→ Icons.app_settings_altdisplaysettings→ Icons.display_settingsengineering→ Icons.engineeringdarkmode→ Icons.dark_mode
Connectivity
wifi→ Icons.wifibluetooth→ Icons.bluetoothbluetoothsearching→ Icons.bluetooth_searchingcelltower→ Icons.cell_towersignalcellularalt→ Icons.signal_cellular_alt
Battery & Power
batterystd→ Icons.battery_stdbatterycharging→ Icons.battery_charging_fullbattery4bar→ Icons.battery_fullbattery1bar→ Icons.battery_1_barbattery0bar→ Icons.battery_0_barpower→ Icons.power
Analytics & Charts
barchart→ Icons.bar_chartanalytics→ Icons.analyticsdatausage→ Icons.data_usageleaderboard→ Icons.leaderboardshowchart→ Icons.show_chart
People & Users
person→ Icons.personpersonoutline→ Icons.person_outlinepeople→ Icons.peoplepeopleoutline→ Icons.people_outlineadminpanelsettings→ Icons.admin_panel_settings
Authentication
login→ Icons.loginlogout→ Icons.logout
Shapes & Design
formatshapes→ Icons.format_shapesshapeline→ Icons.shape_linehexagon→ Icons.hexagoncategory→ Icons.category
Notifications & Alerts
alarm→ Icons.alarmalarmoff→ Icons.alarm_offnotificationsnone→ Icons.notifications_nonenotificationsactive→ Icons.notifications_activenotifications→ Icons.notificationswarning→ Icons.warningdangerous→ Icons.dangerouswarningamber→ Icons.warning_amber_roundedpriorityhigh→ Icons.priority_highreport→ Icons.reportannouncement→ Icons.announcementfeedback→ Icons.feedback
Weather & Time
sun→ Icons.wb_sunnymoon→ Icons.nightlight_round
Other
domain→ Icons.domainsensors→ Icons.sensorsmenu→ Icons.menumore→ 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:
- Fork the repository
- Create a feature branch
- Add your changes with tests
- 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