app_parameters.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import 'dart:convert';
  2. import 'package:fis_common/logger/logger.dart';
  3. import 'package:flutter/foundation.dart';
  4. import 'package:flutter/services.dart';
  5. /// 应用参数(随编译引入)
  6. class AppParameters {
  7. static const _path = "assets/app_params.json";
  8. static late final AppParameterDataModel _data;
  9. static bool _hasLoaded = false;
  10. /// 数据内容
  11. static AppParameterDataModel get data => _data;
  12. /// 加载预置参数数据
  13. static Future<void> load() async {
  14. if (_hasLoaded) return;
  15. try {
  16. final dynamic jsonMap;
  17. final json = await rootBundle.loadString(_path, cache: false);
  18. jsonMap = jsonDecode(json);
  19. _data = AppParameterDataModel.fromJson(jsonMap);
  20. } catch (e) {
  21. logger.e("Load AppConfig error.", e);
  22. _data = AppParameterDataModel();
  23. }
  24. _hasLoaded = true;
  25. }
  26. }
  27. class AppParameterDataModel {
  28. // ignore: constant_identifier_names
  29. static const C_DEFAULT_GATEWAY =
  30. "https://platform.xinglinghui.com:9400"; // TODO:
  31. static const C_HOME_PAGE_URL = "http://192.168.6.80:8408"; // TODO:
  32. static const C_LOCAL_STATION = false;
  33. static const C_PURE_SOFTWAREMODE = false;
  34. static const C_EXCEL_IMPORTURL = "https://platform.xinglinghui.com:9314";
  35. AppParameterDataModel({
  36. this.serverGateway = C_DEFAULT_GATEWAY,
  37. this.homePageUrl = C_HOME_PAGE_URL,
  38. this.isLocalStation = C_LOCAL_STATION,
  39. this.isPureSoftwareMode = C_PURE_SOFTWAREMODE,
  40. this.excelImportUrl = C_EXCEL_IMPORTURL,
  41. });
  42. factory AppParameterDataModel.fromJson(Map<String, dynamic> map) {
  43. final homePageUrl = map['home_page_url'] ?? C_HOME_PAGE_URL;
  44. final isLocalStation = map['local_station'] ?? C_LOCAL_STATION;
  45. final isPureSoftwareMode =
  46. kIsWeb && (map['pure_software_mode'] ?? C_PURE_SOFTWAREMODE);
  47. final serverGetway = isLocalStation
  48. ? map['server_local_gateway']
  49. : map['server_gateway'] ?? C_DEFAULT_GATEWAY;
  50. final excelImportUrl = map["excel_import_url"] ?? C_EXCEL_IMPORTURL;
  51. return AppParameterDataModel(
  52. serverGateway: serverGetway,
  53. homePageUrl: homePageUrl,
  54. isLocalStation: isLocalStation,
  55. isPureSoftwareMode: isPureSoftwareMode,
  56. excelImportUrl: excelImportUrl,
  57. );
  58. }
  59. String serverGateway;
  60. String homePageUrl;
  61. ///Excel 导入站点
  62. String excelImportUrl;
  63. ///是否本地工作站,默认false,如果设置为true,将会在App启动时轮询调用成功Server的接口才会进行登录,否则将会一直处于Splash页面
  64. bool isLocalStation;
  65. ///是否纯软件模式,目前仅在web和Windows下使用
  66. bool isPureSoftwareMode;
  67. }