从这里,我可以看到Google帐单库具有productDetails.subscriptionofferdetails,但是In_app_purchase似乎没有类似的东西可以获取提供并有条件地显示价格。 我试图这样做,然后我导入了这些,并找到了一个称为subscriptionOffersDetailswrapper的对象,但我似乎无法以我想要的方式使用它。
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
import 'package:in_app_purchase_android/billing_client_wrappers.dart';
final ProductDetailsResponse response =
await _inAppPurchase.queryProductDetails(_kIds);
if (response.error != null) {
// Handle the error
}
if (response.productDetails.isEmpty) {
print("why empty");
}
for(var x in response.productDetails){
if(x is GooglePlayProductDetails){
offer = SubscriptionOfferDetailsWrapper(basePlanId: basePlanId, offerTags: offerTags, offerIdToken: offerIdToken, pricingPhases: pricingPhases)
}
}
我如何通过Google Play订阅有条件地在我的Flutter应用程序中显示要约?假设我通过订阅创建了一个报价,可以为用户提供10%的折扣,但是只有那些在我的应用程序中将体育列为自己的爱好的用户。在要约的资格标准中,我选择了确定开发人员。 但我如何在扑朔迷离中实际实现?
使用flutter中获取和应用开发人员确定的订阅优惠。
步骤:
取得订阅提供
GooglePlayProductDetails
final response = await InAppPurchase.instance.queryProductDetails({'your_subscription_id'});
for (var product in response.productDetails) {
if (product is GooglePlayProductDetails) {
for (var offer in product.subscriptionOfferDetails ?? []) {
if (offer.offerTags.contains("sports_hobby_offer")) {
print("Eligible for offer: ${offer.pricingPhases.pricingPhaseList.first.formattedPrice}");
}
}
}
}