app_parameters.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import 'dart:convert';
  2. import 'package:fis_common/logger/logger.dart';
  3. import 'package:flutter/services.dart';
  4. /// 应用参数(随编译引入)
  5. class AppParameters {
  6. static const _path = "assets/app_params.json";
  7. static late final AppParameterDataModel _data;
  8. static bool _hasLoaded = false;
  9. /// 数据内容
  10. static AppParameterDataModel get data => _data;
  11. /// 加载预置参数数据
  12. static Future<void> load() async {
  13. if (_hasLoaded) return;
  14. try {
  15. final dynamic jsonMap;
  16. final json = await rootBundle.loadString(_path, cache: false);
  17. jsonMap = jsonDecode(json);
  18. _data = AppParameterDataModel.fromJson(jsonMap);
  19. } catch (e) {
  20. logger.e("Load AppConfig error.", e);
  21. _data = AppParameterDataModel();
  22. }
  23. _hasLoaded = true;
  24. }
  25. }
  26. class AppParameterDataModel {
  27. // ignore: constant_identifier_names
  28. static const C_DEFAULT_GATEWAY =
  29. "https://platform.xinglinghui.com:9400"; // TODO:
  30. static const C_HOME_PAGE_URL = "http://192.168.6.80:8408"; // TODO:
  31. AppParameterDataModel({
  32. this.serverGateway = C_DEFAULT_GATEWAY,
  33. this.homePageUrl = C_HOME_PAGE_URL,
  34. });
  35. factory AppParameterDataModel.fromJson(Map<String, dynamic> map) {
  36. return AppParameterDataModel(
  37. serverGateway: map['server_gateway'] ?? C_DEFAULT_GATEWAY,
  38. homePageUrl: map['home_page_url'] ?? C_HOME_PAGE_URL,
  39. );
  40. }
  41. String serverGateway;
  42. String homePageUrl;
  43. }