report_editor_configuration.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'dart:convert';
  2. import 'package:fis_common/logger/logger.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/architecture/storage/text_storage.dart';
  5. import 'entity/report_editor_setting.dart';
  6. /// 本地报告编辑器服务
  7. class LocalReportEditorService extends GetxService {
  8. String _cache = "";
  9. /// 获取设置的缓存
  10. void restoreLocalCache() {
  11. try {
  12. var map = json.decode(_cache);
  13. ReportEditorSetting.ins.setDataFromJson(map);
  14. } catch (e) {
  15. logger.e('LocalReportEditorService restoreLocalCache ex:', e);
  16. }
  17. }
  18. static const _SETTING_FILENAME = "local_report_editor_setting.conf";
  19. TextStorage _entryStorage = TextStorage(fileName: _SETTING_FILENAME);
  20. ///初始化
  21. Future<void> init() async {
  22. // 创建实例
  23. final list = await _entryStorage.read();
  24. if (list == null) {
  25. _cache = "";
  26. } else {
  27. _cache = list;
  28. restoreLocalCache();
  29. }
  30. }
  31. ///保存配置
  32. Future<bool> save() async {
  33. var jsonStr = json.encode(ReportEditorSetting.ins.toJson());
  34. return _entryStorage.save(jsonStr);
  35. }
  36. }