Flutter Generate Assets
English | 中文
A VSCode extension that generates Dart asset constants from your Flutter project's pubspec.yaml.
Features
- Manual trigger — run from the command palette, status bar, or context menu
- File watching — optionally regenerates when assets change (disabled by default)
- Image hover preview — hover over any asset constant to see a thumbnail (optional)
- Smart naming — converts file paths to camelCase including directory segments; automatically appends file extension to disambiguate same-named files in different formats (e.g.
copyToClipboardPng / copyToClipboardSvg)
- Format-safe — generated file includes
// dart format off to prevent formatter interference
- Resolution-aware — ignores
2x, 3x, 1.5x resolution variant directories automatically
Usage
Trigger generation via any of the following:
Cmd+Shift+P → Flutter: Generate Assets
- Right-click
pubspec.yaml in the Explorer → Flutter: Generate Assets
- Open
pubspec.yaml and click the ⟳ icon in the editor title bar
- Click the
⟳ Assets button in the status bar
Configuration
Add a flutter_generate_assets section to the root of your pubspec.yaml:
flutter_generate_assets:
output: lib/common/assets.dart # default: lib/generated/assets.dart
class_name: Assets # default: Assets
flutter:
assets:
- assets/images/
- assets/icons/
VSCode settings:
| Setting |
Default |
Description |
flutterGenerateAssets.watchEnabled |
false |
Auto-regenerate on file changes |
flutterGenerateAssets.hoverPreviewEnabled |
false |
Show image thumbnails on hover |
Generated Output
Given the configuration above, the extension generates lib/common/assets.dart:
// GENERATED CODE - DO NOT MODIFY BY HAND
// Generated by Flutter Generate Assets VSCode Extension
// https://github.com/ceeyang/flutter_generate_assets
// ignore_for_file: lines_longer_than_80_chars, constant_identifier_names
// dart format off
class Assets {
static const String imagesLogo = 'assets/images/logo.png';
static const String imagesBgHome = 'assets/images/bg_home.jpg';
static const String iconsArrowLeft = 'assets/icons/arrow-left.svg';
}
When two files share the same name but have different extensions, the extension is automatically appended to distinguish them:
// assets/copy_to_clipboard.png + assets/copy_to_clipboard.svg →
static const String copyToClipboardPng = 'assets/copy_to_clipboard.png';
static const String copyToClipboardSvg = 'assets/copy_to_clipboard.svg';
Requirements
- VSCode 1.85.0 or later
- A Flutter project with
pubspec.yaml at the workspace root
License
MIT