12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import 'package:lszlgl/plugin/flavor_plugin.dart';
- import 'package:lszlgl/service/jgpush_service.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);
- JGPushService.jgInit(env);
- }
- /// 初始化环境
- static Future<AppEnvironment> _initEnv() async {
- // 获取flavor
- var name = await FlavorPlugin.instance.getFlavor();
- // 转为环境数据
- return switch (name) {
- 'develop' => AppEnvironment.develop,
- 'product' => AppEnvironment.product,
- _ => AppEnvironment.product,
- };
- }
- }
|