diff --git a/lib/logic/collectibles_logic.dart b/lib/logic/collectibles_logic.dart index 6328f61a..e57a9df0 100644 --- a/lib/logic/collectibles_logic.dart +++ b/lib/logic/collectibles_logic.dart @@ -1,11 +1,10 @@ import 'dart:convert'; -import 'package:home_widget/home_widget.dart'; +import 'package:http/http.dart' as http; import 'package:wonders/common_libs.dart'; import 'package:wonders/logic/common/platform_info.dart'; import 'package:wonders/logic/common/save_load_mixin.dart'; import 'package:wonders/logic/data/collectible_data.dart'; -import 'package:http/http.dart' as http; import 'package:wonders/logic/native_widget_service.dart'; class CollectiblesLogic with ThrottledSaveLoadMixin { @@ -42,7 +41,7 @@ class CollectiblesLogic with ThrottledSaveLoadMixin { statesById.value = states; if (state == CollectibleState.discovered) { final data = fromId(id)!; - _updateHomeWidgetTextData( + _updateNativeWidgetTextData( title: data.title, id: data.id, imageUrl: data.imageUrlSmall, @@ -58,11 +57,9 @@ class CollectiblesLogic with ThrottledSaveLoadMixin { if (state == CollectibleState.explored) _exploredCount++; }); final foundCount = discoveredCount + exploredCount; - if (PlatformInfo.isIOS) { - _nativeWidget.save('discoveredCount', foundCount).then((value) { - _nativeWidget.markDirty(); - }); - } + _nativeWidget.save('discoveredCount', foundCount).then((value) { + _nativeWidget.markDirty(); + }); debugPrint('setting discoveredCount for home widget $foundCount'); } @@ -95,13 +92,15 @@ class CollectiblesLogic with ThrottledSaveLoadMixin { for (int i = 0; i < all.length; i++) { states[all[i].id] = CollectibleState.lost; } - _updateHomeWidgetTextData(); // clear home widget data + if (_nativeWidget.isSupported) { + _updateNativeWidgetTextData(); // clear home widget data + } statesById.value = states; debugPrint('collection reset'); scheduleSave(); } - Future _updateHomeWidgetTextData({String title = '', String id = '', String imageUrl = ''}) async { + Future _updateNativeWidgetTextData({String title = '', String id = '', String imageUrl = ''}) async { // Save title await _nativeWidget.save('lastDiscoveredTitle', title); // Subtitle diff --git a/lib/logic/native_widget_service.dart b/lib/logic/native_widget_service.dart index ae86086f..b66dbc00 100644 --- a/lib/logic/native_widget_service.dart +++ b/lib/logic/native_widget_service.dart @@ -6,15 +6,15 @@ class NativeWidgetService { static const _iosAppGroupId = 'group.com.gskinner.flutter.wonders.widget'; static const _iosAppName = 'WonderousWidget'; - static final bool _isSupported = PlatformInfo.isIOS; + final bool isSupported = PlatformInfo.isIOS; Future init() async { - if (!_isSupported) return; + if (!isSupported) return; await HomeWidget.setAppGroupId(_iosAppGroupId); } Future save(String s, T value, {void Function(bool?)? onSaveComplete}) async { - if (!_isSupported) return false; + if (!isSupported) return false; return await HomeWidget.saveWidgetData(s, value).then((value) { onSaveComplete?.call(value); return null; @@ -22,7 +22,7 @@ class NativeWidgetService { } Future markDirty() async { - if (!_isSupported) return false; + if (!isSupported) return false; return await HomeWidget.updateWidget(iOSName: _iosAppName); } }