bloomBUILD•SHIP•BLOOM
.md
Type-Safe Configuration

Config & Environment

Manage API base URLs, feature flags, and secret keys across development, staging, and production environments with zero runtime crashes.

.env Configuration

Define environment variables in root .env files:

.env
bash
# .env
API_BASE_URL=https://api.bloom.dev/v1
ENABLE_ANALYTICS=true
AUTH_DOMAIN=auth.bloom.dev
SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0

Typed BloomConfig Class

Subclass BloomConfig to define type-safe accessors with fallbacks:

lib/app/config.dart
dart
// lib/app/config.dart
import 'package:bloom_framework/bloom.dart';

class AppConfig extends BloomConfig {
  late final String apiBaseUrl = getString('API_BASE_URL', defaultValue: 'http://localhost:8080');
  late final bool enableAnalytics = getBool('ENABLE_ANALYTICS', defaultValue: false);
  late final String authDomain = getString('AUTH_DOMAIN');
  late final String? sentryDsn = getOptionalString('SENTRY_DSN');

  AppConfig.fromEnvironment() : super.fromEnvironment();
}

Dependency Injection Access

Usage Example
dart
// Injected anywhere via DI
final config = inject<AppConfig>();
print(config.apiBaseUrl); // Type-safe string access