asset_image_generator 1.0.0 copy "asset_image_generator: ^1.0.0" to clipboard
asset_image_generator: ^1.0.0 copied to clipboard

retracted

A Dart plugin to generate app_images.dart file with static constants for all asset images

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, eliminating hardcoded strings and improving maintainability.

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
  • 📊 Includes complete list of all assets
  • ⚙️ Customizable output location

Installation #

Add to your project's pubspec.yaml:

dev_dependencies:
  asset_image_generator: ^1.0.0

Then run:

flutter pub get

Usage #

Command Line #

Run 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();

  // With custom output path:
  // await AssetImageGenerator().generate(
  //   outputPath: 'lib/constants/images.dart'
  // );
}

Example Output #

lib/generated/app_images.dart:

// GENERATED CODE - DO NOT MODIFY BY HAND
// Generated by asset_image_generator

class AppImages {
  AppImages._();

  /// assets/images/logo.png
  static const String logo = 'assets/images/logo.png';

  /// assets/icons/home.svg
  static const String homeIcon = 'assets/icons/home.svg';

  static const List<String> all = [
    logo,
    homeIcon,
  ];
}

Using Generated Assets #

import 'package:flutter/material.dart';
import 'package:my_app/generated/app_images.dart';

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Image.asset(AppImages.logo);
  }
}

Configuration #

Ensure your pubspec.yaml has proper asset declarations:

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

The generator will automatically:

  • Create the output directory if needed
  • Convert Windows paths to forward slashes
  • Sort assets alphabetically

Best Practices #

  • Add to CI: Include generation in your build process
  • Version Control: Commit the generated file
  • Regenerate: Run after adding new images
  • Organize Assets: Use clear directory structure
  • Use Constants: Always reference via AppImages

Troubleshooting #

No assets found

  • Verify asset paths in pubspec.yaml
  • Ensure directories exist
  • Check for supported file extensions

Path issues on Windows

  • The plugin automatically converts backslashes to forward slashes.

Contributing #

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

License #

MIT © Abhilash Puthukkudi

3
likes
0
points
41
downloads

Publisher

unverified uploader

Weekly Downloads

A Dart plugin to generate app_images.dart file with static constants for all asset images

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

path, yaml

More

Packages that depend on asset_image_generator