string_to_icon 1.0.0

SDKflutter
Platformandroidioswindowslinuxmacosweb

A Flutter package that converts string icon names to IconData objects from the Material Icons set.

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 allIcons = IconMapper.getSupportedIconNames();

// 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