Skip to content

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

Step 1: Generate the Asset Package

bash
archipelago generate flutter_asset

You will be prompted for:

  • appNameMyApp (your application name)
  • prefixApp (prefix for asset class names)
  • isForMonorepotrue
  • includeGeneratedfalse (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.json

Step 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.json

Step 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-gen

Step 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

CustomizationWhere to Change
Add new asset categoriesCreate new dirs in assets/ and regenerate
Change enum naming prefixprefix variable during generation
Include assets in gitSet includeGenerated: true during generation
Add themed asset variantsCreate subdirectories per theme in assets/

Next Steps

Built by Banua Coder