asset_to_dart 0.1.0
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 #
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:
-
Go to File β Settings β Tools β External Tools.
-
Click + to add a new tool:
- Name:
asset_to_dart - Program:
dart - Arguments:
run asset_to_dart - Working directory:
$ProjectFileDir$
- Name:
-
Save and close.
-
Now go to File β Settings β Keymap.
-
Search for your tool name (
asset_to_dart), right-click β Add Keyboard Shortcut, and assign your preferred key combo. -
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:
- Press
Ctrl + Shift + P - Type: Tasks: Configure Task
- Select Create tasks.json from template
- 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"
}
]
}
Option B β Using FVM (Recommended for FVM projects) #
{
"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 #
-
Open File β Preferences β Keyboard Shortcuts
-
Search for:
Run Task -
Assign a shortcut.
-
Select your
asset_to_darttask.
π 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