resolveBaseUrl function

String resolveBaseUrl({
  1. required AppEnvironment environment,
})

Resolves the API base URL for environment from the loaded .env file, applying the https:// scheme used by both staging and production.

Throws a StateError if base_url is missing or empty in the .env file for environment.

Implementation

String resolveBaseUrl({required AppEnvironment environment}) {
  final String baseUrl = dotenv.maybeGet('base_url') ?? '';

  if (baseUrl.isEmpty) {
    throw StateError('base_url is missing or empty in .env-${environment.name}');
  }

  return baseUrl.startsWith('http') ? baseUrl : 'https://$baseUrl';
}