import 'package:flutter/foundation.dart'; import 'package:wonders/logic/common/json_prefs_file.dart'; import 'package:wonders/logic/common/throttler.dart'; mixin ThrottledSaveLoadMixin { late final _file = JsonPrefsFile(fileName); final _throttle = Throttler(const Duration(seconds: 2)); Future load() async { final results = await _file.load(); try { copyFromJson(results); } on Exception catch (e) { debugPrint(e.toString()); } } Future save() async { debugPrint('Saving...'); try { await _file.save(toJson()); } on Exception catch (e) { debugPrint(e.toString()); } } Future scheduleSave() async => _throttle.call(save); /// Serialization String get fileName; Map toJson(); void copyFromJson(Map value); }