import 'dart:convert'; import 'package:fis_common/logger/logger.dart'; import 'package:get/get.dart'; import 'package:vitalapp/architecture/storage/text_storage.dart'; import 'entity/report_editor_setting.dart'; /// 本地报告编辑器服务 class LocalReportEditorService extends GetxService { String _cache = ""; /// 获取设置的缓存 void restoreLocalCache() { try { var map = json.decode(_cache); ReportEditorSetting.ins.setDataFromJson(map); } catch (e) { logger.e('LocalReportEditorService restoreLocalCache ex:', e); } } static const _SETTING_FILENAME = "local_report_editor_setting.conf"; TextStorage _entryStorage = TextStorage(fileName: _SETTING_FILENAME); ///初始化 Future init() async { // 创建实例 final list = await _entryStorage.read(); if (list == null) { _cache = ""; } else { _cache = list; restoreLocalCache(); } } ///保存配置 Future save() async { var jsonStr = json.encode(ReportEditorSetting.ins.toJson()); return _entryStorage.save(jsonStr); } }