init method
Load the ledger from SharedPreferences. Safe to call multiple times —
subsequent calls are no-ops unless the key changes, in which case the
ledger re-loads against the new key.
storageKey — override to isolate state (e.g. per flavor or per user).
Implementation
Future<void> init({String storageKey = defaultStorageKey}) async {
if (_initialized && _storageKey == storageKey) return;
_storageKey = storageKey;
final prefs = await SharedPreferences.getInstance();
final raw = prefs.getString(_storageKey);
if (raw != null) {
final decoded = jsonDecode(raw) as Map<String, dynamic>;
_seen = _readIntMap(decoded['seen']);
_asked = _readIntMap(decoded['asked']);
_counters = _readIntMap(decoded['counters']);
} else {
_seen = {};
_asked = {};
_counters = {};
}
_initialized = true;
}