app_config.dart 972 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import 'package:lszlgl/plugin/flavor_plugin.dart';
  2. import 'package:lszlgl/service/jgpush_service.dart';
  3. import 'package:package_info_plus/package_info_plus.dart';
  4. import '../network/my_api.dart';
  5. enum AppEnvironment {
  6. /// 开发环境
  7. develop,
  8. /// 生产环境
  9. product,
  10. }
  11. class AppConfig {
  12. AppConfig._();
  13. /// 环境信息
  14. static late AppEnvironment env;
  15. /// 包信息
  16. static late PackageInfo packageInfo;
  17. static Future<void> init() async {
  18. packageInfo = await PackageInfo.fromPlatform();
  19. env = await _initEnv();
  20. /// 初始化网络请求
  21. MyApi.init(env);
  22. JGPushService.jgInit(env);
  23. }
  24. /// 初始化环境
  25. static Future<AppEnvironment> _initEnv() async {
  26. // 获取flavor
  27. var name = await FlavorPlugin.instance.getFlavor();
  28. // 转为环境数据
  29. return switch (name) {
  30. 'develop' => AppEnvironment.develop,
  31. 'product' => AppEnvironment.product,
  32. _ => AppEnvironment.product,
  33. };
  34. }
  35. }