Emerson
Emerson

Reputation: 996

Flutter In-App Purchases: How to Retrieve Detailed Subscription Plan Info Like Period and Specific Plan IDs?

How can I get, in Flutter and using the in_app_purchases, the information of the available plans of a subscription to present for the user to choose from?

I need two things:

  1. get the plan subscription id
  2. get the plan subscription period (1 month, 6 months and 1 year)

I have one subscription (id = "no_ads") and 3 plans (ids = "1-year-sub", "6-months", "monthly")

The way it is now, the product object returned by the code below has only the id , title and description from the subscription, and only the price of the plan. Please help 🙁🙁🙁

The way I used it returns the same info in the Product, just varying the price. Is there a way to return the subscription period when getting the products? Even the ID returned is the one from the subscription and not the one from the plan. For the time being I'm testing against google play subscription.

My code on the initialize of my PurchaseProvider is like this:

final response = await _iap.queryProductDetails({"no_ads")}; //my subscription id     
if (response.error == null) {
     _products = response.productDetails..sort((a, b) => a.rawPrice.compareTo(b.rawPrice));
}

On my subscription page I have:

...
SizedBox(height: 5),
            ...purchaseProvider.products.map((product) {
              bool isPurchased = purchaseProvider.isSubscribed &&
                  purchaseProvider.subscribedProductId ==
                      product.id; // Check if this product is purchased
              return ListTile(
                title: Text(
                    "${product.title} \n- Desc: ${product.description} \n- ID: ${product.id}"),
                subtitle: Text(product.description),
                trailing: isPurchased
                    ? Icon(Icons.check, color: Colors.green)
                    : ElevatedButton(
                        onPressed: () {
                          purchaseProvider.buyProduct(product);
                        },
                        child: Text(product.price),
                      ),
              );
            }).toList(),

Below is the subscription screen, and as you can see, the id value is the same for all the three items (plans). enter image description here

Upvotes: 2

Views: 290

Answers (0)

Related Questions