Fix bug where widget would get out of sync w/ app once collected artifacts were explored

This commit is contained in:
Shawn 2024-01-18 11:22:31 -07:00
parent 97cb83733c
commit 590e542b34

View File

@ -57,10 +57,11 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
if (state == CollectibleState.discovered) _discoveredCount++; if (state == CollectibleState.discovered) _discoveredCount++;
if (state == CollectibleState.explored) _exploredCount++; if (state == CollectibleState.explored) _exploredCount++;
}); });
HomeWidget.saveWidgetData<int>('discoveredCount', _discoveredCount).then((value){ final foundCount = discoveredCount + exploredCount;
HomeWidget.saveWidgetData<int>('discoveredCount', foundCount).then((value) {
HomeWidget.updateWidget(iOSName: _appName); HomeWidget.updateWidget(iOSName: _appName);
}); });
debugPrint('setting discovered count for home widget $_discoveredCount'); debugPrint('setting discoveredCount for home widget $foundCount');
} }
/// Get a discovered item, sorted by the order of wondersLogic.all /// Get a discovered item, sorted by the order of wondersLogic.all
@ -102,7 +103,7 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
await HomeWidget.saveWidgetData<String>('lastDiscoveredTitle', title); await HomeWidget.saveWidgetData<String>('lastDiscoveredTitle', title);
// Subtitle // Subtitle
String subTitle = ''; String subTitle = '';
if(id.isNotEmpty){ if (id.isNotEmpty) {
final artifactData = await artifactLogic.getArtifactByID(id); final artifactData = await artifactLogic.getArtifactByID(id);
subTitle = artifactData?.date ?? ''; subTitle = artifactData?.date ?? '';
} }
@ -110,7 +111,7 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
// Image, // Image,
// Download, convert to base64 string and write to shared widget data // Download, convert to base64 string and write to shared widget data
String imageBase64 = ''; String imageBase64 = '';
if(imageUrl.isNotEmpty){ if (imageUrl.isNotEmpty) {
var bytes = await http.readBytes(Uri.parse(imageUrl)); var bytes = await http.readBytes(Uri.parse(imageUrl));
imageBase64 = base64Encode(bytes); imageBase64 = base64Encode(bytes);
debugPrint('Saving base64 bytes: $imageBase64'); debugPrint('Saving base64 bytes: $imageBase64');