Asset Image Generator for Flutter

Pub Version License: MIT Build Status PRs Welcome

A Flutter plugin that automatically generates type-safe Dart references for all your asset images โ€” now with folder-based class generation in v2.0.0.


๐ŸŽ‰ What's New in v3.1.0

  • ๐Ÿ“‚ Generates separate Dart files for each asset folder
  • ๐Ÿ”  Class names based on folder structure (e.g., IconsImages, BackgroundsImages)
  • ๐Ÿ“› Variables for both full paths and image names: home and homeName

โš ๏ธ Breaking Changes: If you're upgrading from v1.x, see Migration Guide โ†’


โœจ Features

  • ๐Ÿ” Scans pubspec.yaml for asset paths automatically
  • ๐Ÿ— Generates clean, type-safe Dart constants
  • ๐Ÿ–ผ Supports PNG, JPG, JPEG, GIF, BMP, WEBP, and SVG formats
  • ๐Ÿ”  Converts filenames to consistent camelCase variables
  • ๐Ÿ“ Works across Windows, macOS, and Linux
  • ๐Ÿ“Š Lists all assets and names for dynamic use
  • โš™๏ธ Customizable output location
  • ๐Ÿงฉ Folder-based organization with tree-shakable structure

๐Ÿš€ Installation

Add to your project's pubspec.yaml under dev_dependencies:

dev_dependencies:
  asset_image_generator: ^2.0.0

Then run:

flutter pub get

โš™๏ธ Usage

๐Ÿ”ง Command Line

From your project root:

flutter pub run asset_image_generator:generate_images

๐Ÿง‘โ€๐Ÿ’ป Programmatic Usage

import 'package:asset_image_generator/asset_image_generator.dart';

void main() async {
  await AssetImageGenerator().generate();

  // OR with custom output path
  // await AssetImageGenerator().generate(
  //   outputPath: 'lib/generated/images/'
  // );
}

๐Ÿ“ Example Output Structure

lib/generated/images/
โ”œโ”€โ”€ images.dart              # Main export file
โ”œโ”€โ”€ app_images.dart          # Root level images
โ”œโ”€โ”€ icons_images.dart        # From assets/icons/
โ”œโ”€โ”€ backgrounds_images.dart  # From assets/backgrounds/

๐Ÿ” Accessing Assets

Option 1: Through Images main class

import 'package:your_app/generated/images/images.dart';

Image.asset(Images.icons.home);             // Full path
print(Images.icons.homeName);               // Just the name

Option 2: Direct import from specific class

import 'package:your_app/generated/images/icons_images.dart';

Image.asset(IconsImages.home);
print(IconsImages.getPathByName('home'));

โœ… Configuration

Ensure your pubspec.yaml has proper asset declarations:

flutter:
  assets:
    - assets/icons/
    - assets/images/
    - assets/backgrounds/

๐Ÿ›  Best Practices

  • โœ… Add this to your CI build process
  • โœ… Commit generated files to version control
  • ๐Ÿ” Regenerate assets after adding new files
  • ๐Ÿงน Keep assets organized in folders

๐Ÿ“„ Supported Extensions

  • .png, .jpg, .jpeg, .gif, .bmp, .webp, .svg

๐Ÿ› Troubleshooting

No assets found?

  • Check that folders exist and are listed in pubspec.yaml
  • Only supported image extensions are picked up

Paths not working on Windows?

  • Generator normalizes paths with forward slashes (/)

๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repo
  2. Create a feature branch
  3. Open a pull request

๐Ÿ“œ License

MIT ยฉ Abhilash Puthukkudi


๐Ÿ“ฆ Pub.dev

๐Ÿ‘‰ View on pub.dev โ†’