Skip to content

shared_app_config Free

Centralized configuration package for environment variables and flavor management using envied for obfuscated compile-time env var injection.

Version: 1.0.0

Variables

VariableTypeDefaultDescription
appNamestringMyAppThe name of your application
isForMonorepobooleantrueWhether this is being generated as part of a monorepo

Usage

Interactive

bash
archipelago generate shared_app_config

Non-interactive (CI)

bash
archipelago generate shared_app_config --config my_config.json

Config Template

json
{
  "@appName": "The name of your application",
  "appName": "MyApp",
  "@isForMonorepo": "Whether this is being generated as part of a monorepo",
  "isForMonorepo": true
}

Generated Structure

shared/
└── app_config/
    ├── .env.development        # Source values for dev flavor (gitignored)
    ├── .env.staging            # Source values for staging flavor (gitignored)
    ├── .env.production         # Source values for production flavor (gitignored)
    ├── .env                    # ACTIVE — written by env switch (gitignored)
    ├── .env.example            # Template showing required variable names
    ├── build.yaml
    ├── lib/
    │   ├── app_config.dart     # Barrel export
    │   └── src/
    │       ├── env/
    │       │   ├── env.dart    # Single @Envied(path: '.env') class
    │       │   ├── env.g.dart  # Generated (obfuscated XOR-encoded values)
    │       │   └── app_env.dart # Public wrapper delegating to Env
    │       └── flavor.dart     # FlavorStatus enum
    ├── analysis_options.yaml
    └── pubspec.yaml

How env works

app_config uses a build-time flavor swap model. A single Env class reads from the .env file at the package root:

dart
@Envied(path: '.env', obfuscate: true, useConstantCase: true)
abstract final class Env {
  @EnviedField()
  static final String apiBaseUrl = _Env.apiBaseUrl;

  @EnviedField()
  static final String aesKey = _Env.aesKey;
}

Each flavor keeps its own source file (.env.development, .env.staging, .env.production). Before building, env switch copies the correct source file to .env so build_runner picks up only that flavor's secrets. Production binaries never contain development or staging secrets.

Access values in application code through AppEnv:

dart
final baseUrl = AppEnv.apiBaseUrl;
final appName = AppEnv.appName;

Build-time env swap

Switch the active flavor before running build_runner and the Flutter build:

bash
# Select the flavor
dart run monorepo_toolkit env switch development

# Regenerate env.g.dart from .env
dart run build_runner build --delete-conflicting-outputs

# Build
flutter build apk --flavor development

See the Environment Sync guide for the full env switch reference, CI integration examples, and the security model.

Adding environment variables

  1. Add @EnviedField() to env.dart (or run dart run monorepo_toolkit env add MY_VAR)
  2. Add the key to all .env.<flavor> files with flavor-specific values
  3. Run dart run monorepo_toolkit env switch <current_flavor>
  4. Run dart run build_runner build --delete-conflicting-outputs

Built by Banua Coder