Setting Up the Asset Package
What you'll learn
- Generating a type-safe asset package with pure Dart contracts
- Understanding the asset_core and Flutter asset enum split
- Adding SVG icons, Lottie animations, and image assets
- Referencing assets from any feature package
Prerequisites
- An existing Archipelago monorepo (see Monorepo Scaffolding)
Step 1: Generate the Asset Package
bash
archipelago generate flutter_assetYou will be prompted for:
- appName —
MyApp(your application name) - prefix —
App(prefix for asset class names) - isForMonorepo —
true - includeGenerated —
false(whether generated files go into git)
Or use a config file:
json
{
"appName": "MyApp",
"prefix": "App",
"isForMonorepo": true,
"includeGenerated": false
}bash
archipelago generate flutter_asset --config asset_config.jsonStep 2: Understand the Generated Structure
The brick generates two complementary packages:
packages/
├── my_app_asset_core/
│ └── lib/src/
│ ├── asset_contract.dart # Pure Dart asset interface
│ ├── asset_type.dart # Asset type enum (svg, png, lottie)
│ └── asset_path_resolver.dart # Path resolution logic
└── my_app_assets/
├── lib/
│ ├── my_app_assets.dart # Barrel exports
│ └── src/
│ └── generated/
│ ├── svg_assets.dart # Generated SVG enum
│ ├── png_assets.dart # Generated PNG enum
│ └── lottie_assets.dart # Generated Lottie enum
└── assets/
├── svg/ # SVG icon files
│ ├── ic_home.svg
│ └── ic_profile.svg
├── png/ # Raster images
└── lottie/ # Lottie JSON animations
└── loading.jsonStep 3: Add Assets and Generate Enums
Drop asset files into the appropriate directories, then generate type-safe enums:
bash
# Add your SVG/PNG/Lottie files to assets/ directories, then:
dart run devtools asset-genStep 4: Use Assets in Features
Reference assets with compile-time safety from any feature package:
dart
import 'package:my_app_assets/my_app_assets.dart';
// SVG icons
SvgPicture.asset(AppSvgAsset.icHome.path);
// Lottie animations
Lottie.asset(AppLottieAsset.loading.path);
// PNG images
Image.asset(AppPngAsset.bgHeader.path);The asset_core package provides pure Dart contracts, making assets accessible in non-Flutter packages (e.g., for path lookups in business logic tests).
Key Customization Points
| Customization | Where to Change |
|---|---|
| Add new asset categories | Create new dirs in assets/ and regenerate |
| Change enum naming prefix | prefix variable during generation |
| Include assets in git | Set includeGenerated: true during generation |
| Add themed asset variants | Create subdirectories per theme in assets/ |
Next Steps
- Set up asset generation for automated enum creation
- Optimize assets to reduce app bundle size
- Generate a UI Kit that uses these assets