string_to_icon 1.0.0
string_to_icon: ^1.0.0 copied to clipboard
A simple, lightweight Flutter package to map string names to Material Design Icons, with fallback support for unknown icons.
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