From 3df9aa0bec2d3d95535f18ab5e216c8ec317b6ff Mon Sep 17 00:00:00 2001 From: JiWoong Sul Date: Mon, 20 Oct 2025 15:05:37 +0900 Subject: [PATCH] =?UTF-8?q?=ED=99=98=EA=B2=BD=20=EB=B3=80=EC=88=98=20?= =?UTF-8?q?=EB=A1=9C=EB=8D=94=20=EA=B2=BD=EB=A1=9C=20=ED=99=95=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/.env.development | 2 +- lib/core/config/environment.dart | 25 +++++++++++++++---------- pubspec.yaml | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/assets/.env.development b/assets/.env.development index a95529b..067030c 100644 --- a/assets/.env.development +++ b/assets/.env.development @@ -1,4 +1,4 @@ -API_BASE_URL=http://localhost:8080 +API_BASE_URL=http://43.201.34.104:8080 TIMEOUT_MS=15000 LOG_LEVEL=debug diff --git a/lib/core/config/environment.dart b/lib/core/config/environment.dart index 0017fae..970860f 100644 --- a/lib/core/config/environment.dart +++ b/lib/core/config/environment.dart @@ -33,17 +33,22 @@ class Environment { envName = envFromDefine.toLowerCase(); isProduction = envName == 'production'; - final fileName = '.env.$envName'; + final candidates = ['.env.$envName', 'assets/.env.$envName']; var initialized = false; - try { - await dotenv.load(fileName: fileName); - initialized = true; - } catch (e) { - if (kDebugMode) { - // 개발 편의를 위해 파일 미존재 시 경고만 출력하고 진행 - // 실제 배포에서는 파일 존재가 필수다. - // ignore: avoid_print - print('[Environment] $fileName 로드 실패: $e'); + + for (final fileName in candidates) { + if (initialized) { + break; + } + try { + await dotenv.load(fileName: fileName); + initialized = true; + } catch (e) { + if (kDebugMode) { + // 웹 번들 자산(.env.*)까지 순차 시도 후 실패 시에만 기본값으로 폴백한다. + // ignore: avoid_print + print('[Environment] $fileName 로드 실패: $e'); + } } } diff --git a/pubspec.yaml b/pubspec.yaml index 8b2504b..84363fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -76,6 +76,7 @@ flutter: assets: - assets/.env.development + - assets/.env.production # To add assets to your application, add an assets section, like this: # assets: