返回列表
技术
67 分钟
Flutter CI/CD 与发布流程
Site Owner
发布于 2026-05-22
系统讲解Flutter GitHub Actions/Codemagic CI配置、iOS证书与Android签名、Fastlane自动化及灰度发布策略

Flutter CI/CD 与发布流程 (CI/CD & Release)
模块:模块十 · 架构与工程化
前置知识:Flutter 构建命令、Git 基础、测试基础
Flutter 多环境配置
使用 --dart-define 区分环境
# 三套环境(开发/测试/生产)
# 使用 --dart-define 传递编译时常量(比 .env 文件更安全,不会打入 APK)
# 开发环境
flutter run \
--dart-define=ENV=development \
--dart-define=API_URL=https://dev-api.example.com \
--dart-define=ENABLE_LOGS=true
# 测试环境
flutter run \
--dart-define=ENV=staging \
--dart-define=API_URL=https://staging-api.example.com \
--dart-define=ENABLE_LOGS=true
# 生产环境
flutter build apk \
--dart-define=ENV=production \
--dart-define=API_URL=https://api.example.com \
--dart-define=ENABLE_LOGS=false \
--release
// lib/core/config/app_config.dart
class AppConfig {
// 从编译时常量读取,若未定义使用默认值
static const String env = String.fromEnvironment(
'ENV',
defaultValue: 'development',
);
static const String apiUrl = String.fromEnvironment(
'API_URL',
defaultValue: 'https://dev-api.example.com',
);
static const bool enableLogs = bool.fromEnvironment(
'ENABLE_LOGS',
defaultValue: true,
);
// 便捷 getter
static bool get isProduction => env == 'production';
static bool get isDevelopment => env == 'development';
static bool get isStaging => env == 'staging';
}