2

I am using in_app_purchase, version 3.1.7 in flutter. And the purchases for subscription works well. But their is no documentation on how I can check if the current user have an active subscription.

I have tried to make this code but I am missing something:

  Future<void> loadSubscriptions() async {
    final Set<String> subscriptionIds = <String>{'premium'};
    final ProductDetailsResponse response =
        await _inAppPurchase.queryProductDetails(subscriptionIds);
    final List<ProductDetails> subscriptions = response.productDetails;
    print(subscriptions);
  }

  void _listenToPurchaseUpdateV1(
      List<PurchaseDetails> purchaseDetailsList) async {
    purchaseDetailsList.forEach((PurchaseDetails purchaseDetails) async {
      if (purchaseDetails.status == PurchaseStatus.purchased) {
        if (purchaseDetails.pendingCompletePurchase == true) {
          _isSubscribed = true;
        } else {
          _isSubscribed = false;
        }
      } else if (purchaseDetails.status == PurchaseStatus.error) {
        print("ERROR ERROR");
      }
    });
  }

  Future<void> checkSubscriptionStatus() async {
    var app = _inAppPurchase.purchaseStream;
    app.listen(_listenToPurchaseUpdateV1, onDone: () {
      setState(() {
        _isSubscribed;
      });
    });
  }

I was looking in another thread for answers but did not find any. Was checking this one: Flutter how to use in_app_purchase plugin to implement subsciptions?

nologic
  • 25
  • 4

0 Answers0