chatapp3-flutter/lib/app/config/app_config.dart
2026-04-09 21:32:23 +08:00

162 lines
3.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/foundation.dart';
import 'package:yumi/app/config/configs/sc_variant1_config.dart';
import 'package:yumi/app/config/business_logic_strategy.dart';
/// 应用配置基类
/// 定义单一应用配置接口
abstract class AppConfig {
/// 应用显示名称
String get appName;
/// 包名/应用ID
String get packageName;
/// API服务器地址
String get apiHost;
/// 图片服务器地址
String get imgHost;
/// 隐私协议URL
String get privacyAgreementUrl;
/// 用户协议URL
String get userAgreementUrl;
/// 应用下载链接Google Play
String get appDownloadUrlGoogle;
/// 应用下载链接App Store
String get appDownloadUrlApple;
/// 主播代理URL
String get anchorAgentUrl;
/// 主持人中心URL
String get hostCenterUrl;
/// BD中心URL
String get bdCenterUrl;
/// BD领导中心URL
String get bdLeaderUrl;
/// 代币销售URL
String get coinSellerUrl;
/// 管理员URL
String get adminUrl;
/// 代理中心URL
String get agencyCenterUrl;
/// 游戏国王URL
String get gamesKingUrl;
/// 财富榜URL
String get wealthRankUrl;
/// 魅力榜URL
String get charmRankUrl;
/// 房间榜URL
String get roomRankUrl;
/// 邀请新用户URL
String get inviteNewUserUrl;
/// 主题主颜色
int get primaryColor;
/// 腾讯IM App ID
String get tencentImAppid;
/// Agora RTC App ID
String get agoraRtcAppid;
/// 游戏App ID
num get gameAppid;
/// 游戏渠道
String get gameAppChannel;
/// 全服广播大群ID
String get bigBroadcastGroup;
/// 管理账号
String get imAdmin;
/// 是否审核模式
bool get isReview;
/// 礼物特效开关
bool get isGiftSpecialEffects;
/// 入场秀开关
bool get isEntryVehicleAnimation;
/// 全局飘屏开关
bool get isFloatingAnimationInGlobal;
/// 幸运礼物特效开关
bool get isLuckGiftSpecialEffects;
/// 获取功能开关
Map<String, bool> get featureFlags;
/// 获取业务逻辑策略
BusinessLogicStrategy get businessLogicStrategy;
/// 获取所有配置的Map用于调试
Map<String, dynamic> toMap();
/// 验证配置是否有效
/// 检查必要的配置项是否已正确设置
/// 如果配置无效,抛出 [StateError]
void validate();
/// 当前应用的配置实例
static AppConfig? _current;
/// 从环境变量获取variant配置
/// 支持通过--dart-define=VARIANT=variant2传递参数
/// 默认使用variant1
static String _getVariant() {
const variant = String.fromEnvironment('VARIANT', defaultValue: 'variant1');
return variant;
}
/// 获取当前配置实例
static AppConfig get current {
if (_current == null) {
throw StateError(
'AppConfig not initialized. Call AppConfig.initialize() first.',
);
}
return _current!;
}
/// 初始化应用配置
/// 支持通过环境变量选择variantvariant1或variant2
/// 使用--dart-define=VARIANT=variant2传递参数
static void initialize() {
final variant = _getVariant();
switch (variant) {
case 'variant1':
default:
_current = SCVariant1Config();
debugPrint('AppConfig initialized for variant1 ');
}
// 验证配置是否有效
try {
_current!.validate();
} catch (e) {
// validate方法在调试模式下不会抛出异常
// 只有在发布模式下验证失败才会抛出异常
debugPrint('应用配置验证失败: $e');
rethrow;
}
}
}