import 'dart:convert'; import 'dart:io'; /// Where user preferences (theme, key bindings) are kept between runs. abstract class SettingsStore { Map load(); void save(Map data); } /// Keeps nothing (tests, previews). class MemorySettings implements SettingsStore { Map data = {}; @override Map load() => data; @override void save(Map d) => data = d; } /// A small JSON file; unreadable or corrupt files just mean defaults. class FileSettings implements SettingsStore { FileSettings(this.path); final String path; @override Map load() { try { final v = jsonDecode(File(path).readAsStringSync()); return v is Map ? v : {}; } catch (_) { return {}; } } @override void save(Map data) { try { File(path).writeAsStringSync(jsonEncode(data)); } catch (_) {} } }