Template
Core 基础设施:Flavor 三包体系、Drift+SQLCipher 加密数据库 7 拦截器 Dio 网络栈、CrashReporter 崩溃日志、Sealed Failure 错误体系 5 色板主题系统、Auth 认证骨架(Clean Architecture)、Dev Panel、Mock Adapter 通过验证:flutter analyze(0 errors)、flutter test(全绿)、staging APK 74.8MB
44 lines
1.9 KiB
Dart
44 lines
1.9 KiB
Dart
import 'package:sunny_mochi/core/config/env.dart';
|
||
|
||
/// API 网络配置 — **baseUrl 决策的单一权威**
|
||
///
|
||
/// **对应 iOS BasicModule/Configuration/NetworkConfig.swift(2026-05 同步)**:
|
||
///
|
||
/// | 环境 | iOS apiBaseURL | Flutter ApiConfig.baseUrl |
|
||
/// |------|---------------|--------------------------|
|
||
/// | dev | http://192.168.1.201:24801 | 同 |
|
||
/// | test | https://dev.yixiong-tech.com:8081 | 同 |
|
||
/// | release | https://bac.new.hamkke.top | 同 |
|
||
///
|
||
/// **优先级**:
|
||
/// 1. CI/CD / 临时调试通过 `--dart-define=API_BASE_URL=...` 注入 → 优先
|
||
/// 2. 否则按 `Env.name`(dev/test/release)返回 iOS 同源 URL
|
||
///
|
||
/// **不再引入 h5BaseURL** — H5 评估报告已全部 Flutter 原生化(详见
|
||
/// docs/h5-to-native-decision-2026-05-10.md),不再需要 in-app WebView。
|
||
///
|
||
/// **响应码请用 [ResponseCode]**(lib/core/network/response_code.dart)。
|
||
/// **API 路径请用 [ApiPaths]**(lib/core/config/api_paths.dart)—
|
||
/// 不允许 datasource 散落字面量。
|
||
abstract class ApiConfig {
|
||
/// API 网关 baseUrl — 与 iOS NetworkConfig.swift 同源
|
||
static String get baseUrl {
|
||
// 1. dart-define 覆盖优先(CI/CD / 临时切换私有环境)
|
||
if (Env.apiBaseUrlOverride.isNotEmpty) {
|
||
return Env.apiBaseUrlOverride;
|
||
}
|
||
// 2. 按 Env.name 返回 iOS 同源 URL
|
||
return switch (Env.name) {
|
||
'dev' => 'http://192.168.1.201:24801',
|
||
'test' => 'https://dev.yixiong-tech.com:8081',
|
||
'release' => 'https://bac.new.hamkke.top',
|
||
_ => 'http://192.168.1.201:24801', // 默认 dev(与 iOS Debug 包一致)
|
||
};
|
||
}
|
||
|
||
// 网络超时 — 对应共性需求说明 §移动端 7.网络异常处理(10s 超时建议)
|
||
static const Duration connectTimeout = Duration(seconds: 15);
|
||
static const Duration receiveTimeout = Duration(seconds: 30);
|
||
static const Duration sendTimeout = Duration(seconds: 30);
|
||
}
|