Skip to content

Commit

Permalink
[Infrastructure] Added a method to check if a feature is unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Mar 6, 2022
1 parent 89342d5 commit 179f598
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/infrastructure/purchase_service.dart
Expand Up @@ -140,14 +140,6 @@ class PurchaseServiceImpl implements PurchaseService {
@override
Future<List<AppUnlockedFeature>> getUnlockedFeatures() async {
try {
if (!await isPlatformSupported()) {
return [];
}

if (await Purchases.isAnonymous) {
return [];
}

final features = await _getUnlockedFeatures();
return features;
} catch (e, s) {
Expand All @@ -156,8 +148,22 @@ class PurchaseServiceImpl implements PurchaseService {
}
}

@override
Future<bool> isFeatureUnlocked(AppUnlockedFeature feature) async {
final features = await getUnlockedFeatures();
return features.contains(feature);
}

Future<List<AppUnlockedFeature>> _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);
Expand Down

0 comments on commit 179f598

Please sign in to comment.