1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- 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<void> init() async {
- packageInfo = await PackageInfo.fromPlatform();
- env = await _initEnv();
- /// 初始化网络请求
- MyApi.init(env);
- }
- /// 初始化环境
- static Future<AppEnvironment> _initEnv() async {
- // 获取flavor
- var name = await FlavorPlugin.instance.getFlavor();
- // 转为环境数据
- return switch (name) {
- 'develop' => AppEnvironment.develop,
- 'product' => AppEnvironment.product,
- _ => AppEnvironment.product,
- };
- }
- }
|