look ahead
This commit is contained in:
@@ -3,6 +3,7 @@ library;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../models/bank.dart';
|
||||
@@ -16,6 +17,7 @@ class TxMetaStoreData {
|
||||
this.labelsByMerchant = const {},
|
||||
this.notesByMerchant = const {},
|
||||
this.exactTemplates = const {},
|
||||
this.recurringTemplates = const {},
|
||||
this.customLabels = const [],
|
||||
this.labelParents = const {},
|
||||
});
|
||||
@@ -24,6 +26,7 @@ class TxMetaStoreData {
|
||||
final Map<String, List<String>> labelsByMerchant;
|
||||
final Map<String, String> notesByMerchant;
|
||||
final Map<String, TxExactTemplate> exactTemplates;
|
||||
final Map<String, RecurringTemplate> recurringTemplates;
|
||||
final List<TxLabel> customLabels;
|
||||
|
||||
/// childLabelId → parentLabelId (roots omitted).
|
||||
@@ -147,8 +150,9 @@ class StorageService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveBankCache(BankCache cache) {
|
||||
return _prefs.setString(StorageKeys.bankCache, jsonEncode(cache.toJson()));
|
||||
Future<void> saveBankCache(BankCache cache) async {
|
||||
final json = await compute(jsonEncode, cache.toJson());
|
||||
await _prefs.setString(StorageKeys.bankCache, json);
|
||||
}
|
||||
|
||||
Future<void> clearBankCache() {
|
||||
@@ -170,7 +174,7 @@ class StorageService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveImportedTransactions(List<BankTransaction> txs) {
|
||||
Future<void> saveImportedTransactions(List<BankTransaction> txs) async {
|
||||
final encoded = [
|
||||
for (final tx in txs)
|
||||
{
|
||||
@@ -181,10 +185,8 @@ class StorageService {
|
||||
'pending': tx.pending,
|
||||
},
|
||||
];
|
||||
return _prefs.setString(
|
||||
StorageKeys.importedTransactions,
|
||||
jsonEncode(encoded),
|
||||
);
|
||||
final json = await compute(jsonEncode, encoded);
|
||||
await _prefs.setString(StorageKeys.importedTransactions, json);
|
||||
}
|
||||
|
||||
Future<void> clearImportedTransactions() {
|
||||
@@ -225,7 +227,7 @@ class StorageService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveTxMetaStore(TxMetaStoreData store) {
|
||||
Future<void> saveTxMetaStore(TxMetaStoreData store) async {
|
||||
final encoded = {
|
||||
'byId': {
|
||||
for (final e in store.byId.entries) e.key: e.value.toJson(),
|
||||
@@ -247,12 +249,18 @@ class StorageService {
|
||||
'exactTemplates': {
|
||||
for (final e in store.exactTemplates.entries) e.key: e.value.toJson(),
|
||||
},
|
||||
'recurringTemplates': {
|
||||
for (final e in store.recurringTemplates.entries)
|
||||
e.key: e.value.toJson(),
|
||||
},
|
||||
'customLabels': [
|
||||
for (final label in store.customLabels) label.toJson(),
|
||||
],
|
||||
'labelParents': store.labelParents,
|
||||
};
|
||||
return _prefs.setString(StorageKeys.txMeta, jsonEncode(encoded));
|
||||
// jsonEncode of large annotation maps is CPU-heavy — keep it off the UI isolate.
|
||||
final json = await compute(jsonEncode, encoded);
|
||||
await _prefs.setString(StorageKeys.txMeta, json);
|
||||
}
|
||||
|
||||
TxMetaStoreData _decodeStore(String raw) {
|
||||
@@ -326,6 +334,19 @@ class StorageService {
|
||||
});
|
||||
}
|
||||
|
||||
final recurringTemplates = <String, RecurringTemplate>{};
|
||||
final recurringRaw = root['recurringTemplates'];
|
||||
if (recurringRaw is Map) {
|
||||
recurringRaw.forEach((key, value) {
|
||||
if (key is String && value is Map) {
|
||||
final tpl =
|
||||
RecurringTemplate.fromJson(Map<String, dynamic>.from(value));
|
||||
if (tpl.id.isEmpty) return;
|
||||
recurringTemplates[tpl.id.isNotEmpty ? tpl.id : key] = tpl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final customLabels = <TxLabel>[];
|
||||
final customs = root['customLabels'];
|
||||
if (customs is List) {
|
||||
@@ -365,6 +386,7 @@ class StorageService {
|
||||
labelsByMerchant: labelsByMerchant,
|
||||
notesByMerchant: notesByMerchant,
|
||||
exactTemplates: exactTemplates,
|
||||
recurringTemplates: recurringTemplates,
|
||||
customLabels: customLabels,
|
||||
labelParents: labelParents,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user