flutter_asset_gen 0.1.0 copy "flutter_asset_gen: ^0.1.0" to clipboard
flutter_asset_gen: ^0.1.0 copied to clipboard

Fast, configurable Dart/Flutter asset constants generator.

flutter_asset_gen #

pub version license Dart SDK

Fast, configurable, and idempotent asset constants generator for Dart/Flutter projects. Generate strongly-typed constants from your assets/ folders with zero boilerplate.

✨ Features #

  • πŸ“ Multiple asset roots - Support for assets/images, assets/icons, assets/audio, etc.
  • βš™οΈ YAML configuration - Flexible config with asset_gen.yaml
  • πŸ” Smart filtering - Glob patterns, extensions, and exclusions
  • 🎯 Case styles - camel, snake, or keep naming conventions
  • πŸ”„ Idempotent - Only regenerates when files actually change
  • 🚫 Collision handling - Automatic deduplication with warnings
  • πŸ“¦ Pure Dart - No build_runner or Flutter plugin required
  • πŸ—ΊοΈ Optional map export - Generate Map<String,String> of all assets
  • πŸ“Š Grouping - Organize constants by asset root

πŸš€ Quick Start #

1. Install #

Add as a dev dependency:

dev_dependencies:
  flutter_asset_gen: ^0.1.0

2. Configure #

Create asset_gen.yaml in your project root:

roots:
  - assets/images
  - assets/icons
  - assets/audio

output: lib/core/constants/assets.dart
class_name: Assets

exclude:
  - "**/.*"
  - "**/*.DS_Store"

case: camel
group_by_root: true
generate_map: true

3. Run #

dart run flutter_asset_gen

4. Use #

import 'package:your_app/core/constants/assets.dart';

// Use in widgets
Image.asset(Assets.appLogo);
SvgPicture.asset(Assets.playIcon);

// Iterate all assets
Assets.all.forEach((name, path) {
  print('$name: $path');
});

πŸ“‹ Configuration Options #

Option Type Default Description
roots List<String> Required Asset directories to scan
output String Required Output file path
class_name String Assets Generated class name
exclude List<String> [] Glob patterns to exclude
include_extensions List<String> All File extensions to include
case String camel camel, snake, or keep
prefix String "" Prefix for all identifiers
sort String identifier identifier or path
group_by_root bool true Group constants by root
generate_map bool true Generate all map
add_header bool true Add generation header

🧬 Generated Output #

// GENERATED CODE - DO NOT MODIFY
// Run: dart run flutter_asset_gen

class Assets {
  const Assets._();

  // --- assets/images ---
  /// assets/images/logo/app_icon.png
  static const appIcon = "assets/images/logo/app_icon.png";
  
  /// assets/images/background/hero.jpg
  static const heroBackground = "assets/images/background/hero.jpg";

  // --- assets/icons ---
  /// assets/icons/play.svg
  static const play = "assets/icons/play.svg";
  
  /// assets/icons/pause.svg
  static const pause = "assets/icons/pause.svg";

  static const Map<String, String> all = {
    "appIcon": appIcon,
    "heroBackground": heroBackground,
    "play": play,
    "pause": pause,
  };
}

πŸ› οΈ CLI Usage #

# Basic usage
dart run flutter_asset_gen

# Verbose output
dart run flutter_asset_gen --verbose

# Dry run (no file writing)
dart run flutter_asset_gen --dry-run

# Custom config file
dart run flutter_asset_gen --config=config/asset_gen.yaml

# Help
dart run flutter_asset_gen --help

πŸ”§ Advanced Configuration #

Multiple Asset Roots #

roots:
  - assets/images
  - assets/icons
  - assets/audio
  - assets/fonts
  - assets/raw

File Type Filtering #

include_extensions:
  - .png
  - .jpg
  - .jpeg
  - .svg
  - .mp3
  - .wav

Custom Exclusions #

exclude:
  - "**/.*"                    # Hidden files
  - "**/*.DS_Store"           # macOS files
  - "**/temp/**"              # Temp folders
  - "**/*_draft.*"            # Draft files
  - "assets/images/old/**"    # Specific folders

Naming Conventions #

# camelCase (default)
case: camel
# Result: appIcon, playButton, heroBackground

# snake_case
case: snake
# Result: app_icon, play_button, hero_background

# keep original
case: keep
# Result: app_icon, play_button, hero_background

# With prefix
case: camel
prefix: asset
# Result: assetAppIcon, assetPlayButton

🚦 Workflow Integration #

Git Hooks #

Add to your pre-commit hook:

#!/bin/bash
dart run flutter_asset_gen
git add lib/core/constants/assets.dart

CI/CD #

# GitHub Actions example
- name: Generate assets
  run: dart run flutter_asset_gen

- name: Check for changes
  run: |
    git diff --exit-code lib/core/constants/assets.dart || \
    (echo "Asset constants need regeneration. Run 'dart run flutter_asset_gen'" && exit 1)

πŸ§ͺ Development #

# Run tests
dart test

# Format code
dart format .

# Analyze code
dart analyze

🀝 Contributing #

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (dart test)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

πŸ“„ License #

This project is licensed under the MIT License - see the LICENSE file for details.

⭐ Support #

If this package helps you, please give it a star! ⭐


Made with ❀️ for the Flutter community

2
likes
0
points
110
downloads

Publisher

unverified uploader

Weekly Downloads

Fast, configurable Dart/Flutter asset constants generator.

Repository (GitHub)
View/report issues

Topics

#flutter #assets #generator #codegen #cli

Documentation

Documentation

License

unknown (license)

Dependencies

crypto, glob, path, yaml

More

Packages that depend on flutter_asset_gen