VooConfig
Build-time configuration code generation for Flutter. Generates type-safe Dart code from .env or .config files at compile time.
Important Security Notice
This package is for CONFIGURATION, not secrets.
| Use VooConfig For | Use VooSecrets For |
|---|---|
| Base URLs | API keys with write access |
| Feature flags | Database credentials |
| API versions | Signing keys |
| Debug mode toggles | Payment processor keys |
| Analytics IDs | Any sensitive credentials |
Values generated by VooConfig are embedded directly in your app binary and can be extracted by anyone with access to your app. For secrets, use the voo_secrets package which fetches values from a secure backend at runtime.
Features
- Build-Time Generation - Configuration compiled directly into Dart code
- Type Support - Parse values as
String,int,double, orbool - Multi-Environment - Support for
.env.development,.env.staging,.env.production - Type-Safe API - Generated code provides compile-time type safety
- No Runtime Overhead - Values are constants, no file parsing at runtime
Installation
Add to your pubspec.yaml:
dependencies:
voo_config: ^1.0.0
dev_dependencies:
voo_config_generator: ^1.0.0
build_runner: ^2.4.0
Quick Start
1. Create a configuration file
# .env
BASE_URL=https://api.example.com
API_VERSION=2
DEBUG_MODE=true
MAX_RETRIES=3
2. Create a config class
import 'package:voo_config/voo_config.dart';
part 'config.voo_config.g.dart';
@VooConfig()
abstract class Config {
@ConfigField()
static const String baseUrl = _Config.baseUrl;
@ConfigField(type: ConfigType.int)
static const int apiVersion = _Config.apiVersion;
@ConfigField(type: ConfigType.bool)
static const bool debugMode = _Config.debugMode;
@ConfigField(type: ConfigType.int)
static const int maxRetries = _Config.maxRetries;
}
3. Generate code
dart run build_runner build --delete-conflicting-outputs
4. Use in your app
import 'config.dart';
void main() {
print('API: ${Config.baseUrl}/v${Config.apiVersion}');
print('Debug: ${Config.debugMode}');
runApp(MyApp());
}
API Reference
@VooConfig
Class annotation to enable code generation.
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
String |
.env |
Path to the config file |
name |
String? |
null |
Custom name for generated class |
allowOptionalFields |
bool |
false |
Allow nullable fields by default |
useConstantCase |
bool |
false |
Convert camelCase to CONSTANT_CASE |
@ConfigField
Field annotation to configure individual values.
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
String? |
null |
Custom config var name to look up |
type |
ConfigType |
string |
Value type (string, int, double, bool) |
optional |
bool? |
null |
Allow null if config var is missing |
defaultValue |
Object? |
null |
Default value for optional fields |
Multi-Environment Support
Create separate config files for each environment:
// config_development.dart
@VooConfig(path: '.env.development')
abstract class ConfigDevelopment {
@ConfigField()
static const String baseUrl = _ConfigDevelopment.baseUrl;
}
// config_production.dart
@VooConfig(path: '.env.production')
abstract class ConfigProduction {
@ConfigField()
static const String baseUrl = _ConfigProduction.baseUrl;
}
CI/CD Integration
Since VooConfig is a build-time generator, create config files from CI secrets:
# GitHub Actions example
- name: Create config files
run: |
echo "BASE_URL=${{ secrets.BASE_URL }}" >> .env.production
echo "API_VERSION=${{ secrets.API_VERSION }}" >> .env.production
- run: flutter pub get
- run: dart run build_runner build --delete-conflicting-outputs
- run: flutter build apk --release
Testing
Run tests:
dart test
Migration from voo_env
If you're migrating from voo_env:
- Replace
voo_envwithvoo_configin dependencies - Replace
voo_env_generatorwithvoo_config_generator - Rename annotations:
@VooEnv→@VooConfig@EnvField→@ConfigFieldEnvType→ConfigType
- Remove
obfuscateparameter (no longer supported) - For secrets, migrate to
voo_secretspackage
License
MIT License - see LICENSE file for details.
Built by VooStack
Need help with Flutter development or secure configuration?
VooStack builds enterprise Flutter applications and developer tools.
Libraries
- voo_config
- Build-time configuration code generation for Flutter.