app_config.dart 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. /// 初始化极光推送
  23. JGPushService.jgInit(env);
  24. }
  25. /// 初始化环境
  26. static Future<AppEnvironment> _initEnv() async {
  27. // 获取flavor
  28. var name = await FlavorPlugin.instance.getFlavor();
  29. // 转为环境数据
  30. return switch (name) {
  31. 'develop' => AppEnvironment.develop,
  32. 'product' => AppEnvironment.product,
  33. _ => AppEnvironment.product,
  34. };
  35. }
  36. }