Tweak collectibles logic to await data writing
This commit is contained in:
parent
395fa12ad0
commit
97cb83733c
@ -38,6 +38,8 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
|
|||||||
|
|
||||||
void setState(String id, int state) {
|
void setState(String id, int state) {
|
||||||
Map<String, int> states = Map.of(statesById.value);
|
Map<String, int> states = Map.of(statesById.value);
|
||||||
|
states[id] = state;
|
||||||
|
statesById.value = states;
|
||||||
if (state == CollectibleState.discovered) {
|
if (state == CollectibleState.discovered) {
|
||||||
final data = fromId(id)!;
|
final data = fromId(id)!;
|
||||||
_updateHomeWidgetTextData(
|
_updateHomeWidgetTextData(
|
||||||
@ -46,8 +48,6 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
|
|||||||
imageUrl: data.imageUrlSmall,
|
imageUrl: data.imageUrlSmall,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
states[id] = state;
|
|
||||||
statesById.value = states;
|
|
||||||
scheduleSave();
|
scheduleSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,14 +99,14 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
|
|||||||
|
|
||||||
Future<void> _updateHomeWidgetTextData({String title = '', String id = '', String imageUrl = ''}) async {
|
Future<void> _updateHomeWidgetTextData({String title = '', String id = '', String imageUrl = ''}) async {
|
||||||
// Save title
|
// Save title
|
||||||
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 ?? '';
|
||||||
}
|
}
|
||||||
HomeWidget.saveWidgetData<String>('lastDiscoveredSubTitle', subTitle);
|
await HomeWidget.saveWidgetData<String>('lastDiscoveredSubTitle', subTitle);
|
||||||
// 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 = '';
|
||||||
@ -115,8 +115,8 @@ class CollectiblesLogic with ThrottledSaveLoadMixin {
|
|||||||
imageBase64 = base64Encode(bytes);
|
imageBase64 = base64Encode(bytes);
|
||||||
debugPrint('Saving base64 bytes: $imageBase64');
|
debugPrint('Saving base64 bytes: $imageBase64');
|
||||||
}
|
}
|
||||||
HomeWidget.saveWidgetData<String>('lastDiscoveredImageData', imageBase64);
|
await HomeWidget.saveWidgetData<String>('lastDiscoveredImageData', imageBase64);
|
||||||
HomeWidget.updateWidget(iOSName: _appName);
|
await HomeWidget.updateWidget(iOSName: _appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: wonders
|
name: wonders
|
||||||
description: Explore the famous wonders of the world.
|
description: Explore the famous wonders of the world.
|
||||||
publish_to: "none"
|
publish_to: "none"
|
||||||
version: 2.1.0
|
version: 2.1.1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.17.0 <3.0.0"
|
sdk: ">=2.17.0 <3.0.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user