app_config.dart 888 B

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