fix: 修复 Flutter Web 生产环境 API 地址未生效的问题

- NetworkConfig.baseUrl 改为使用 ApiEndpoints.baseUrl
- 确保构建时 --dart-define=ENV=prod 能正确切换环境

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 02:26:10 +08:00
parent 5c3dbc149a
commit a27ee426db
4 changed files with 79 additions and 3 deletions

75
flutter_monisuo/BUILD.md Normal file
View File

@@ -0,0 +1,75 @@
# Flutter 构建说明
## 环境配置
| 环境 | ENV | API 地址 |
|------|-----|----------|
| 开发 | `dev` | `http://localhost:5010` |
| 生产 | `prod` | `http://8.155.172.147:5010` |
## Web 构建
```bash
# 开发环境(默认)
flutter run -d chrome
# 生产构建
flutter build web --release --dart-define=ENV=prod
```
输出目录:`build/web/`
## Android 构建
```bash
# APK (用于测试分发)
flutter build apk --release --dart-define=ENV=prod
# App Bundle (用于上架 Google Play)
flutter build appbundle --release --dart-define=ENV=prod
# 分架构构建 (减小体积)
flutter build apk --release --dart-define=ENV=prod --split-per-abi
```
输出目录:`build/app/outputs/`
## iOS 构建
```bash
# 需要 macOS
flutter build ios --release --dart-define=ENV=prod
```
## 常用参数
| 参数 | 说明 |
|------|------|
| `--release` | 生产模式,优化体积和性能 |
| `--debug` | 调试模式,含完整调试信息 |
| `--profile` | 性能分析模式 |
| `--dart-define=ENV=prod` | 设置生产环境 |
| `--split-per-abi` | 分架构构建 APK |
| `--wasm` | 启用 WebAssembly (实验性) |
## 代码中判断环境
```dart
import 'core/constants/api_endpoints.dart';
if (ApiEndpoints.isProduction) {
// 生产环境逻辑
} else {
// 开发环境逻辑
}
```
## 部署 Web
```bash
# 构建后上传 build/web 目录到服务器
scp -r build/web/* user@server:/var/www/html/
# 或使用 nginx 托管
# 将 build/web 目录配置为 nginx 静态资源目录
```