- Add AppConfig class for dev/prod environment settings - Create main_dev.dart and main_prod.dart entry points - Update datasources to use centralized API URL config - Support --dart-define=ENV for runtime configuration
56 lines
1.5 KiB
Dart
56 lines
1.5 KiB
Dart
/// Application configuration for different environments.
|
|
///
|
|
/// This class provides environment-specific settings like API URLs
|
|
/// and logging levels, supporting both development and production builds.
|
|
class AppConfig {
|
|
final String apiBaseUrl;
|
|
final bool enableLogging;
|
|
final String environment;
|
|
|
|
const AppConfig._({
|
|
required this.apiBaseUrl,
|
|
required this.enableLogging,
|
|
required this.environment,
|
|
});
|
|
|
|
/// Development configuration (uses local backend)
|
|
static const AppConfig dev = AppConfig._(
|
|
apiBaseUrl: 'http://10.0.2.2:8000', // Android emulator localhost
|
|
enableLogging: true,
|
|
environment: 'development',
|
|
);
|
|
|
|
/// Production configuration (Linode VPS)
|
|
static const AppConfig prod = AppConfig._(
|
|
apiBaseUrl: 'http://172.104.152.69',
|
|
enableLogging: false,
|
|
environment: 'production',
|
|
);
|
|
|
|
/// Current active configuration (set at app startup)
|
|
static AppConfig _current = dev;
|
|
|
|
/// Get the current configuration
|
|
static AppConfig get current => _current;
|
|
|
|
/// Initialize configuration from dart-define or default to dev
|
|
static void initialize({String? environment}) {
|
|
const envFromDefine = String.fromEnvironment('ENV', defaultValue: 'dev');
|
|
final env = environment ?? envFromDefine;
|
|
|
|
switch (env) {
|
|
case 'prod':
|
|
case 'production':
|
|
_current = prod;
|
|
break;
|
|
case 'dev':
|
|
case 'development':
|
|
default:
|
|
_current = dev;
|
|
}
|
|
}
|
|
|
|
@override
|
|
String toString() => 'AppConfig(env: $environment, api: $apiBaseUrl)';
|
|
}
|