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
| Variable | Type | Default | Description |
|---|---|---|---|
| appName | string | MyApp | The name of your application |
| isForMonorepo | boolean | true | Whether this is being generated as part of a monorepo |
Usage
Interactive
archipelago generate shared_app_configNon-interactive (CI)
archipelago generate shared_app_config --config my_config.jsonConfig Template
{
"@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.yamlHow env works
app_config uses a build-time flavor swap model. A single Env class reads from the .env file at the package root:
@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:
final baseUrl = AppEnv.apiBaseUrl;
final appName = AppEnv.appName;Build-time env swap
Switch the active flavor before running build_runner and the Flutter build:
# 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 developmentSee the Environment Sync guide for the full env switch reference, CI integration examples, and the security model.
Adding environment variables
- Add
@EnviedField()toenv.dart(or rundart run monorepo_toolkit env add MY_VAR) - Add the key to all
.env.<flavor>files with flavor-specific values - Run
dart run monorepo_toolkit env switch <current_flavor> - Run
dart run build_runner build --delete-conflicting-outputs