QProduct constructor

QProduct(
  1. String qonversionId,
  2. String? storeId,
  3. String? basePlanId,
  4. SkuDetailsWrapper? skuDetails,
  5. QProductStoreDetails? storeDetails,
  6. SKProductWrapper? skProduct,
  7. String? offeringId,
  8. QSubscriptionPeriod? subscriptionPeriod,
  9. QSubscriptionPeriod? trialPeriod,
  10. QProductType type,
  11. String? prettyPrice,
)

Implementation

QProduct(
    this.qonversionId,
    this.storeId,
    this.basePlanId,
    this.skuDetails,
    this.storeDetails,
    this.skProduct,
    this.offeringId,
    this.subscriptionPeriod,
    this.trialPeriod,
    this.type,
    this.prettyPrice,
  ) {
  final skuDetails = this.skuDetails;
  final storeDetails = this.storeDetails;
  final skProduct = this.skProduct;

  if (skProduct != null) {
    storeTitle = skProduct.localizedTitle;
    storeDescription = skProduct.localizedDescription;
    currencyCode = skProduct.priceLocale?.currencyCode;
    price = double.tryParse(skProduct.price) ?? null;

    final SKProductDiscountWrapper? introPrice = skProduct.introductoryPrice;
    final String? currencySymbol = introPrice?.priceLocale?.currencySymbol;
    if (introPrice != null && currencySymbol != null) {
      prettyIntroductoryPrice = currencySymbol + introPrice.price;
    }
  } else {
    var priceMicros;
    if (skuDetails != null) {
      storeTitle = skuDetails.title;
      storeDescription = skuDetails.description;

      priceMicros = skuDetails.priceAmountMicros;
      currencyCode = skuDetails.priceCurrencyCode;

      final String? introPrice = skuDetails.introductoryPrice;
      if (introPrice != null && introPrice.isEmpty) {
        prettyIntroductoryPrice = null;
      } else {
        prettyIntroductoryPrice = introPrice;
      }
    }

    if (storeDetails != null) {
      storeTitle = storeDetails.title;
      storeDescription = storeDetails.description;

      final QProductOfferDetails? defaultOffer = storeDetails.defaultSubscriptionOfferDetails;
      final QProductInAppDetails? inAppOffer = storeDetails.inAppOfferDetails;
      if (defaultOffer != null) {
        priceMicros = defaultOffer.basePlan?.price.priceAmountMicros;
        currencyCode = defaultOffer.basePlan?.price.priceCurrencyCode;
        prettyIntroductoryPrice = defaultOffer.introPhase?.price.formattedPrice;
      } else if (inAppOffer != null) {
        priceMicros = inAppOffer.price.priceAmountMicros;
        currencyCode = inAppOffer.price.priceCurrencyCode;
        prettyIntroductoryPrice = null;
      }
    }

    price = priceMicros == null
        ? null
        : priceMicros / Constants.skuDetailsPriceRatio;
  }
}