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

A CLI tool to auto-generate strongly typed Dart classes for Flutter assets. Supports all-in-one or per-folder output, filtering, and custom output paths.


asset_to_dart #

pub package

A CLI tool to automatically generate strongly typed Dart asset classes for your Flutter projects. No more writing asset paths by handβ€”just generate them once and use them safely everywhere.


✨ Features #

  • Generates Dart classes for assets in your project.
  • Supports both all-in-one file or separate files per folder.
  • Customize which directories to include.
  • Configurable output path.
  • Prevents typo-related runtime errors by using constants.
  • CLI flags for automation, debugging, and flexibility.

πŸ“¦ Installation #

Activate globally from pub.dev:

dart pub global activate asset_to_dart

Or use locally in a project:

dev_dependencies:
  asset_to_dart: ^0.1.0

Run from project root:

dart run asset_to_dart

βš™οΈ Configuration #

You can configure asset generation directly with CLI flags, or via your pubspec.yaml (coming soon πŸš€).

Example project structure:

project_root/
  assets/
    images/
      logo.png
      banner.jpg
    icons/
      home.svg
      settings.svg
  lib/
    generated/
      assets.dart

Generated Dart file (assets.dart):

class Assets {
  static const imagesLogo = "assets/images/logo.png";
  static const imagesBanner = "assets/images/banner.jpg";

  static const iconsHome = "assets/icons/home.svg";
  static const iconsSettings = "assets/icons/settings.svg";
}

πŸš€ Usage #

Run the tool from your project root:

asset_to_dart

CLI Options #

--all-in-one            Generate all assets into a single Dart file (default)
--separate              Generate separate Dart files per directory
--include <paths...>    Include only specific directories
--output <path>         Set output directory (default: lib/generated/assets)
--help, -h              Show help message
--verbose, -v           Enable verbose logging
--pre-class <name>       Prefix for generated class names (default: App).
--post-class <name>      Suffix for generated class names (default: "").

Examples #

Generate all assets into one file:

asset_to_dart --all-in-one

Generate separate files per folder:

asset_to_dart --separate

Include only specific folders:

asset_to_dart --include assets/images assets/icons

Change output directory:

asset_to_dart --output lib/core/assets

Run with debug logs:

asset_to_dart --verbose

⚑ Android Studio Integration #

You can bind the CLI to a keyboard shortcut for faster usage:

  1. Go to File β†’ Settings β†’ Tools β†’ External Tools.

  2. Click + to add a new tool:

    • Name: asset_to_dart
    • Program: dart
    • Arguments: run asset_to_dart
    • Working directory: $ProjectFileDir$
  3. Save and close.

  4. Now go to File β†’ Settings β†’ Keymap.

  5. Search for your tool name (asset_to_dart), right-click β†’ Add Keyboard Shortcut, and assign your preferred key combo.

  6. You can now generate assets directly with your shortcut inside Android Studio πŸŽ‰


Here’s a clean README-ready section you can paste directly under the Android Studio section.

It matches your style and keeps everything consistent πŸ‘Œ


⚑ VS Code / Cursor Integration #

You can run asset_to_dart directly from VS Code or Cursor using Tasks and optionally bind it to a keyboard shortcut.


βœ… Step 1 β€” Create tasks.json #

Inside your project, create:

.vscode/tasks.json

If it doesn’t exist:

  1. Press Ctrl + Shift + P
  2. Type: Tasks: Configure Task
  3. Select Create tasks.json from template
  4. Choose Others

Option A β€” Using system dart #

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "asset_to_dart",
      "type": "shell",
      "command": "dart run asset_to_dart",
      "group": "build"
    }
  ]
}

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "asset_to_dart",
      "type": "shell",
      "command": "fvm dart run asset_to_dart",
      "group": "build"
    }
  ]
}

With flags example:

"command": "fvm dart run asset_to_dart --separate --verbose"

▢️ Run the Task #

  • Press Ctrl + Shift + P
  • Or open Command Palette β†’ Run Task
  • Select: asset_to_dart

🎹 Optional β€” Add a Keyboard Shortcut #

  1. Open File β†’ Preferences β†’ Keyboard Shortcuts

  2. Search for:

    Run Task
    
  3. Assign a shortcut.

  4. Select your asset_to_dart task.


πŸš€ Cursor Users #

Cursor uses the same VS Code task system.

Just create:

.vscode/tasks.json

And use the same configuration shown above.

No additional setup required.


πŸ›  Development #

Clone the repo:

git clone https://github.com/MazenxELGayar/asset_to_dart.git
cd asset_to_dart

Run locally:

dart run bin/asset_to_dart.dart --help

πŸ“„ License #

MIT License Β© 2025 Mazen El-Gayar

0
likes
140
points
93
downloads

Publisher

unverified uploader

Weekly Downloads

A CLI tool to auto-generate strongly typed Dart classes for Flutter assets. Supports all-in-one or per-folder output, filtering, and custom output paths.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

args, yaml

More

Packages that depend on asset_to_dart