This commit is contained in:
1 parent
925a9be18e
commit
ca85b66e87
5 files changed
+85
-52
No files matched your search
@@ -2,9 +2,11 @@
|
||||
|
||||
/// 开发环境配置。
|
||||
///
|
||||
/// 本机联调用:模拟器与桌面端可直接用回环地址,但 iOS/Android 真机必须用
|
||||
/// 开发机的局域网 IP(真机上的 127.0.0.1 指向手机自己)。地址不要带结尾斜杠。
|
||||
/// UAT Debug 默认地址。
|
||||
///
|
||||
/// `uat` 分支的 Debug 包也应访问 UAT 服务,不应回落到开发机局域网地址。
|
||||
/// 地址不要带结尾斜杠。
|
||||
abstract final class DevConfig {
|
||||
/// 开发机后端地址(Mac 当前 Wi-Fi 地址,换网络后需要同步修改)。
|
||||
static const String baseUrl = 'http://192.168.31.120:8081';
|
||||
/// UAT 客户端 API 地址。
|
||||
static const String baseUrl = 'https://drama-api.frostgiant.vip';
|
||||
}
|
||||
@@ -10,6 +10,9 @@ abstract final class ServerEndpoint {
|
||||
/// Preference key used for the runtime server address.
|
||||
static const String preferenceKey = 'dev.api_base_url';
|
||||
|
||||
/// 地址迁移前的开发机默认值;UAT 启动时不能继续使用它。
|
||||
static const String legacyLocalBaseUrl = 'http://192.168.31.120:8081';
|
||||
|
||||
/// Returns a normalized http(s) URL, or null for invalid input.
|
||||
static String? normalize(String? raw) {
|
||||
final value = raw?.trim() ?? '';
|
||||
@@ -38,8 +41,15 @@ abstract final class ServerEndpoint {
|
||||
try {
|
||||
final prefs = preferences ?? SharedPreferencesAsync();
|
||||
final stored = await prefs.getString(preferenceKey);
|
||||
final normalizedStored = normalize(stored);
|
||||
if (normalizedStored == legacyLocalBaseUrl &&
|
||||
normalize(AppConfig.baseUrl) != legacyLocalBaseUrl) {
|
||||
await prefs.remove(preferenceKey);
|
||||
AppConfig.clearRuntimeBaseUrl();
|
||||
return;
|
||||
}
|
||||
AppConfig.applyRuntimeBaseUrl(
|
||||
resolve(stored: stored, fallback: AppConfig.baseUrl),
|
||||
resolve(stored: normalizedStored, fallback: AppConfig.baseUrl),
|
||||
);
|
||||
} catch (_) {
|
||||
AppConfig.clearRuntimeBaseUrl();
|
||||
|
||||
+39
-39
@@ -13,10 +13,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: archive
|
||||
sha256: "0d58d1fa1fddf6588251ccf2819f3fb3b6d0452c1b2813ac7413a05592bfbefe"
|
||||
sha256: "2fda90592c0afd219c5e285618a98da835cd10df38372666093d25dfe457a2d0"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.5.2"
|
||||
version: "4.7.1"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -69,18 +69,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: clock
|
||||
sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b
|
||||
sha256: e51d50bca3217c9a9fa2b41a30e4a38971133f5f9ec7a3d57bae095007f1d28e
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.2"
|
||||
version: "1.1.3"
|
||||
code_assets:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: code_assets
|
||||
sha256: bf394f466ba9205f1812a0433b392d6af280f155f56651eda7c18cc32ed493b8
|
||||
sha256: "1ef22a0be3af9370bd9481ac76db114db92bfe75d5ca2b2d7bc911764478a4d9"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
version: "2.2.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -93,10 +93,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: crypto
|
||||
sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
|
||||
sha256: e3626ae6270383c9e3a549f34c9e4cd26c09ae6a9adaab2bf4737a00340efdc4
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
version: "3.0.8"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -259,10 +259,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: hooks
|
||||
sha256: "9a62a50b50b769a737bc0a8ff381f333529df3ab746b2f6b02e83760231455ba"
|
||||
sha256: eaac480a35ec0814146c2c48d96aaa829e0e44a7662c88ae84c9edf4bc35651f
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
version: "2.2.0"
|
||||
html:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -291,10 +291,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: image
|
||||
sha256: "89ed75b2f8231fe676808c5564f9590d728024ded7ac782a7ed8474f1c95b72a"
|
||||
sha256: bc13f61f0f5cb77936e78ae5dae3800f442718dac5d2bc4654f03c239230ed0c
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.12.0"
|
||||
version: "4.13.1"
|
||||
integration_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@@ -312,10 +312,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: jni
|
||||
sha256: "6b9ca0602fef0230e83149afbe3f9f8227e94f2bbe84a1da4f14d699742f402d"
|
||||
sha256: "2e91e6087291affd10b31b6c872f3e3ac7dc5d93b51b5ba485d930c8f08bde6c"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.1.2"
|
||||
jni_flutter:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -424,10 +424,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: objective_c
|
||||
sha256: b7fb95a6d9a4f009edd63dc5ac69f07420b23a16161c6dd8660290b59c602e8e
|
||||
sha256: c965d264fd4b0b4dd402dce9d049b70656bf98d3ca108b9bc55d2544ceadbe5e
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "9.5.0"
|
||||
version: "9.6.4"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -504,18 +504,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: permission_handler_android
|
||||
sha256: b1ce660f4d0dcaffdf2605a19544c129fb5adda4e6fd039992ae356c4e437039
|
||||
sha256: baf93fbf80008c240b2cf5e6d62e9495ea7727fe327444d135c44bfff9af6b6e
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "14.1.0"
|
||||
version: "14.1.1"
|
||||
permission_handler_apple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: permission_handler_apple
|
||||
sha256: b69e6b8300f9584af5ab81b41cdaa544e1b45e6fca0a30b0f9a9a120d90fc8a5
|
||||
sha256: "82d31c9b321c45785ccd73bce9c63af17037116193b4000b998a4363059adb6e"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "9.6.4"
|
||||
version: "9.6.5"
|
||||
permission_handler_html:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -536,10 +536,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: permission_handler_windows
|
||||
sha256: caeae01858a0a7d2df67a445ac98e1ad95e55a0e77c73044f4e9b1c8c2289cbd
|
||||
sha256: "210031f00c32d61038fb4175d82dd874a426bfbae2c2af774bd4e5abb5cac755"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.2.2"
|
||||
version: "0.2.4"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -568,10 +568,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: posix
|
||||
sha256: bc1bad54ad2b735816e31f8d4600cfde6c7839975085ddfbca48b6c9f7c4044e
|
||||
sha256: "613646d076944f3acc125830af935b48d4b8a57a388691547bbfd25b434f4d63"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.5.2"
|
||||
version: "6.5.4"
|
||||
process:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -600,10 +600,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: record_use
|
||||
sha256: "2551bd8eecfe95d14ae75f6021ad0248be5c27f138c2ec12fcb52b500b3ba1ed"
|
||||
sha256: "1cb8564af8d43b464294411db9217f5ec04891c6f22ee2c32d73ae05e88a6bd2"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.6.0"
|
||||
version: "1.1.1"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -677,10 +677,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1"
|
||||
sha256: "277654b3034d17ac6f9f1cb5595db011b1d5d41e8806866db28e0abaa101c490"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.12.1"
|
||||
version: "1.12.2"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -741,34 +741,34 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
sha256: "92b9910f66ed1057fd4da7b040ae7c74cafacf885bdc81be496928d5049b032d"
|
||||
sha256: fa49e1674cb84acb900141714e6c6e1f9ae099827c24d141430ff6819db4e1bc
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
version: "2.4.4"
|
||||
video_player:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: video_player
|
||||
sha256: "07ae1e03f2d4c8e2e9a75ee678f90acbc4506d4458a9c628512d119a1eee5754"
|
||||
sha256: "48a7bdaa38a3d50ec10c78627abdbfad863fdf6f0d6e08c7c3c040cfd80ae36f"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.14.1"
|
||||
version: "2.11.1"
|
||||
video_player_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: video_player_android
|
||||
sha256: d27054dea34d748a44f06d433a57005d2aac69944485b0abbaed3303dbcfa3f1
|
||||
sha256: "73af648c6fbd0ced6b4863b3ae995bf86e9f976544891d92a3e38452647b91c5"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.12.2"
|
||||
version: "2.12.4"
|
||||
video_player_avfoundation:
|
||||
dependency: transitive
|
||||
dependency: "direct overridden"
|
||||
description:
|
||||
name: video_player_avfoundation
|
||||
sha256: "4f8a845173377ab250a50f9b9dfe4a43500cc76a7c49dd8410d02d8fc29dfd8b"
|
||||
sha256: "436fd029bd1c1e303b2d95ebd76948893f3c28dab286e7235ba9dd7b22533bf0"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.12.1"
|
||||
version: "2.11.1"
|
||||
video_player_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -797,10 +797,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
|
||||
sha256: e119e82ac4795c7925103b7cf3768191f33941b99e7ccffbd6c645201d9f606b
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
version: "1.1.2"
|
||||
webdriver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+6
-1
@@ -36,7 +36,8 @@ dependencies:
|
||||
# 网络层用 dio(统一拦截器/超时/错误映射);纯 Dart 无原生插件,仍然不引代码生成与图片缓存库
|
||||
dio: ^5.7.0
|
||||
provider: ^6.1.5+1
|
||||
video_player: ^2.14.0
|
||||
# Xcode 16.2 不兼容 2.12.x 的 Swift AVFoundation 实现;2.11.1 保持 ObjC 原生实现。
|
||||
video_player: 2.11.1
|
||||
shared_preferences: 2.3.3
|
||||
shared_preferences_android: 2.4.28
|
||||
# 规避 2.6.0 的 Pigeon 生成代码尾随逗号需要新版 Swift。
|
||||
@@ -72,6 +73,10 @@ dev_dependencies:
|
||||
shared_preferences_platform_interface: 2.4.2
|
||||
flutter_native_splash: ^2.4.8
|
||||
|
||||
# Xcode 16.2 cannot compile the Swift 6.2 syntax introduced by avfoundation 2.12.x.
|
||||
dependency_overrides:
|
||||
video_player_avfoundation: 2.11.1
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
||||
@@ -68,21 +68,22 @@ void main() {
|
||||
: ProdConfig.baseUrl;
|
||||
expect(AppConfig.baseUrl, expected);
|
||||
expect(AppConfig.apiBaseUrl, expected);
|
||||
expect(Uri.parse(AppConfig.baseUrl).port, 8081);
|
||||
final port = Uri.parse(AppConfig.baseUrl).port;
|
||||
expect(port, Uri.parse(AppConfig.baseUrl).scheme == 'https' ? 443 : 8081);
|
||||
});
|
||||
|
||||
test('should_keep_dev_and_prod_addresses_in_separate_files', () {
|
||||
final dev = Uri.parse(DevConfig.baseUrl);
|
||||
final prod = Uri.parse(ProdConfig.baseUrl);
|
||||
|
||||
expect(dev.scheme, 'http');
|
||||
expect(dev.host, isNot(prod.host));
|
||||
expect(dev.port, 8081);
|
||||
expect(dev.scheme, 'https');
|
||||
expect(dev.host, 'drama-api.frostgiant.vip');
|
||||
expect(dev.port, 443);
|
||||
expect(dev.path, isEmpty);
|
||||
expect(prod.scheme, 'http');
|
||||
expect(prod.port, 8081);
|
||||
expect(prod.scheme, 'https');
|
||||
expect(prod.port, prod.scheme == 'https' ? 443 : 8081);
|
||||
expect(prod.path, isEmpty);
|
||||
expect(DevConfig.baseUrl, isNot(ProdConfig.baseUrl));
|
||||
expect(DevConfig.baseUrl, ProdConfig.baseUrl);
|
||||
});
|
||||
|
||||
test('should_prefer_runtime_override_over_environment_switch', () {
|
||||
@@ -121,6 +122,21 @@ void main() {
|
||||
expect(AppConfig.apiBaseUrl, 'http://192.168.31.187:8081');
|
||||
});
|
||||
|
||||
test('should_remove_legacy_local_url_when_loading_uat_debug', () async {
|
||||
SharedPreferencesAsyncPlatform.instance =
|
||||
InMemorySharedPreferencesAsync.withData({
|
||||
ServerEndpoint.preferenceKey: ServerEndpoint.legacyLocalBaseUrl,
|
||||
});
|
||||
|
||||
await ServerEndpoint.load(debug: true);
|
||||
|
||||
expect(AppConfig.apiBaseUrl, AppConfig.baseUrl);
|
||||
expect(
|
||||
await SharedPreferencesAsync().getString(ServerEndpoint.preferenceKey),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('should_save_normalized_url_and_clear_override', () async {
|
||||
expect(await ServerEndpoint.save('ftp://invalid'), isFalse);
|
||||
expect(
|
||||
|
||||
Reference in new issue
Block a user