From 179f598972213258106835edeeced6899b846217 Mon Sep 17 00:00:00 2001 From: Efrain Date: Sat, 5 Mar 2022 19:11:55 -0500 Subject: [PATCH] [Infrastructure] Added a method to check if a feature is unlocked --- lib/infrastructure/purchase_service.dart | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/infrastructure/purchase_service.dart b/lib/infrastructure/purchase_service.dart index b852e6d2f..62ef3bae8 100644 --- a/lib/infrastructure/purchase_service.dart +++ b/lib/infrastructure/purchase_service.dart @@ -140,14 +140,6 @@ class PurchaseServiceImpl implements PurchaseService { @override Future> getUnlockedFeatures() async { try { - if (!await isPlatformSupported()) { - return []; - } - - if (await Purchases.isAnonymous) { - return []; - } - final features = await _getUnlockedFeatures(); return features; } catch (e, s) { @@ -156,8 +148,22 @@ class PurchaseServiceImpl implements PurchaseService { } } + @override + Future isFeatureUnlocked(AppUnlockedFeature feature) async { + final features = await getUnlockedFeatures(); + return features.contains(feature); + } + Future> _getUnlockedFeatures({String? entitlementIdentifier}) async { try { + if (!await isPlatformSupported()) { + return []; + } + + if (await Purchases.isAnonymous) { + return []; + } + final transactions = await Purchases.restoreTransactions(); if (entitlementIdentifier.isNullEmptyOrWhitespace) { final activeEntitlements = transactions.entitlements.active.values.any((el) => el.isActive);