import 'package:lszlgl/plugin/flavor_plugin.dart'; import 'package:package_info_plus/package_info_plus.dart'; import '../network/my_api.dart'; enum AppEnvironment { /// 开发环境 develop, /// 生产环境 product, } class AppConfig { AppConfig._(); /// 环境信息 static late AppEnvironment env; /// 包信息 static late PackageInfo packageInfo; static Future init() async { packageInfo = await PackageInfo.fromPlatform(); env = await _initEnv(); /// 初始化网络请求 MyApi.init(env); } /// 初始化环境 static Future _initEnv() async { // 获取flavor var name = await FlavorPlugin.instance.getFlavor(); // 转为环境数据 return switch (name) { 'develop' => AppEnvironment.develop, 'product' => AppEnvironment.product, _ => AppEnvironment.product, }; } }