Start
Setup
- Dart SDK 3.12+
- A normal Flutter / Dart package (
pubspec.yamlat the root)
Install
dev_dependencies only. No runtime API.
dart pub add --dev fast_dev
dart pub add --dev build_runner # skip if CLI-onlyOr by hand:
dev_dependencies:
fast_dev: ^0.0.1-beta.1
build_runner: ^2.7.2Skip build_runner if you only run dart run fast_dev gen. If the project already uses build_runner, adding fast_dev is enough.
Assets still go in pubspec.yaml. Directories are expanded recursively, so one line is usually enough:
flutter:
assets:
- assets/Or list files:
flutter:
assets:
- assets/images/logo.svg
- assets/data/hello.jsonCreate a config file
Put fast_dev_config.yaml next to pubspec.yaml.
The tool can run without it and will use defaults (the CLI mentions that). A file in the repo is clearer: class name, style, and output are visible to everyone.
A small start:
version: 1
generate:
output: lib/gen/fast_dev/
line_length: 80
assets:
class_name: Assets
style: nestedIf you have light / dark or locale folders, turn variants on. Something like example/:
version: 1
generate:
output: lib/gen/fast_dev/
line_length: 80
assets:
class_name: Assets
style: nested
variants:
theme:
enabled: true
locale:
enabled: true
folders:
- zh
- en
fallback: fileHow to create and load the file: Configuration. Field details: Assets. After you write the file:
dart run fast_dev configGenerate
dart run fast_dev genDefault output is lib/gen/fast_dev/assets.gen.dart.
If the project already uses build_runner, one watch is enough. It runs with the other builders:
dart run build_runner watchHow to sit next to them, and build.yaml: build_runner.
Use
import 'package:your_app/gen/fast_dev/assets.gen.dart';
Image.asset(Assets.images.logo);
rootBundle.loadString(Assets.data.hello);
// after theme / locale variants are on
Image.asset(Assets.images.logo.of(context));AssetPath is a String. Image.asset, rootBundle, and your own APIs can take it as-is.