localreporteditorservice.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import 'dart:convert';
  2. import 'package:flyinsonolite/jsonrpc/fisLib/services/log.m.dart';
  3. import 'package:flyinsonolite/infrastructure/logger.dart';
  4. import 'package:flyinsonolite/managers/configurationmanager.dart';
  5. import 'package:flyinsonolite/consultation/reports/models/reporteditsetting.dart';
  6. import 'package:flyinsonolite/services/sharedstorageservice.dart';
  7. import 'package:get/get.dart';
  8. /// 本地报告编辑器服务
  9. class LocalReportEditorService extends GetxService {
  10. String _cache = "";
  11. /// 获取设置的缓存
  12. void restoreLocalCache() {
  13. try {
  14. var map = json.decode(_cache);
  15. ReportEditorSetting.ins.setDataFromJson(map);
  16. } catch (e) {
  17. loggerAsyn(FISDeviceLogCategory.Error,
  18. 'LocalReportEditorService restoreLocalCache ex:$e');
  19. }
  20. }
  21. ///初始化
  22. void init() async {
  23. // 创建实例
  24. final list =
  25. SharedStorageService.ins.getString(StoreKeys.reportEditSetting);
  26. if (list == null) {
  27. _cache = "";
  28. } else {
  29. _cache = list;
  30. restoreLocalCache();
  31. }
  32. }
  33. ///保存配置
  34. Future<bool> saveAsync() async {
  35. var jsonStr = json.encode(ReportEditorSetting.ins.toJson());
  36. return await SharedStorageService.ins
  37. .setString(StoreKeys.reportEditSetting, jsonStr);
  38. }
  39. }