Home / projects / asset icon

Project: Asset Icon

AssetIcon - Customizable Flutter Asset-Based Icon Package

By Hisham ยท Published on November 05, 2024

Description

AssetIcon is a powerful and customizable Flutter package for rendering asset-based icons with ease.

Whether you're working with PNG, SVG, or other formats, this package allows you to adjust properties such as size, color, and opacity.

It also offers batch generation of Dart code for your asset keys, making it easier to manage large sets of icons.

โœจ Features

  1. ๐Ÿ“ Multiple Format Support: Display PNG and SVG icons seamlessly, along with support for other formats.

  2. ๐ŸŽจ Customization: Modify icon size, color, and opacity to fit your app's theme.

  3. ๐Ÿ”ง Global Configuration: Set default path and color for consistent styling.

  4. ๐Ÿ›ก๏ธ Accessibility: Add semantic labels for screen readers.

  5. ๐Ÿš€ Automated Icon Key Generation: Generate constant keys for all icons in your assets folder.

๐Ÿ“ฆ Installation

Add AssetIcon to your pubspec.yaml:

dependencies:
  assets_icon: ^latest_version

๐Ÿ’ป Code Generation

Run the generator with:

dart run asset_icon:generate --source-dir assets/icons/ --class-name MyAssetIcons --output-dir lib/generated --output-file my_icons.g.dart

๐Ÿ“ Example Folder Structure

assets/
โ””โ”€โ”€ icons/
    โ”œโ”€โ”€ example_icon.png
    โ”œโ”€โ”€ example_icon.svg
    โ””โ”€โ”€ other_icon.png

๐Ÿค Contribute

Submit issues or pull requests to improve functionality.

๐Ÿ“œ License

MIT License

Challenges

Managing icons in Flutter projects often becomes complicated when:

  • Working with many files spread across directories.

  • Needing SVG support (not available in ImageIcon).

  • Adjusting opacity or accessibility labels.

  • Maintaining consistency without constants for asset paths.

Solutions

  • AssetIcon solves these problems by:

  • โœ… Supporting both PNG and SVG formats.

  • โœ… Allowing customization of size, color, and opacity.

  • โœ… Adding semantic labels for accessibility.

  • โœ… Providing automated code generation for icon keys, ensuring consistency across the app.