From a3ac007759acba6275877238bfe793a5d79f752f Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Sat, 31 Oct 2026 14:00:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(config):=20release=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BD=BF=E7=94=A8=E7=94=9F=E4=BA=A7=E7=8E=AF?= =?UTF-8?q?=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/config/app_config.dart | 10 +++++----- test/core/app_config_environment_test.dart | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 test/core/app_config_environment_test.dart diff --git a/lib/core/config/app_config.dart b/lib/core/config/app_config.dart index 0727c39..9fc3f53 100644 --- a/lib/core/config/app_config.dart +++ b/lib/core/config/app_config.dart @@ -1,5 +1,7 @@ // Author: fruit.com.cn +import 'package:flutter/foundation.dart'; + import 'dev_config.dart'; import 'prod_config.dart'; @@ -9,12 +11,10 @@ import 'prod_config.dart'; /// - `dev_config.dart`:[DevConfig](本机联调) /// - `prod_config.dart`:[ProdConfig](生产) /// -/// 切换环境只改下面这一个布尔值,不用传任何构建参数、也不做网络探测。 +/// Debug 使用开发环境,Release 自动使用生产环境,不做网络探测。 abstract final class AppConfig { - /// **环境开关**:true 用开发环境,false 用生产环境。 - /// - /// 打生产包前必须改成 false;release 构建若仍为 true 会在启动时直接报错。 - static const bool useDevConfig = true; + /// **环境开关**:Debug 使用开发环境,Release 使用生产环境。 + static const bool useDevConfig = !kReleaseMode; /// 当前选中的环境地址。 static String get baseUrl => diff --git a/test/core/app_config_environment_test.dart b/test/core/app_config_environment_test.dart new file mode 100644 index 0000000..2cce7e2 --- /dev/null +++ b/test/core/app_config_environment_test.dart @@ -0,0 +1,18 @@ +// Author: fruit.com.cn + +// 应用环境选择测试。 +import 'package:flutter/foundation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:fruitshorts/core/config/app_config.dart'; +import 'package:fruitshorts/core/config/dev_config.dart'; +import 'package:fruitshorts/core/config/prod_config.dart'; + +void main() { + test('should_use_environment_matching_build_mode', () { + expect(AppConfig.useDevConfig, !kReleaseMode); + expect( + AppConfig.baseUrl, + kReleaseMode ? ProdConfig.baseUrl : DevConfig.baseUrl, + ); + }); +}