fromProductDetails static method

List<GooglePlayProductDetails> fromProductDetails(
  1. ProductDetailsWrapper productDetails
)

Generates a list of GooglePlayProductDetails based on an Android ProductDetailsWrapper object.

If productDetails is of type ProductType.inapp, a single GooglePlayProductDetails will be constructed. If productDetails is of type ProductType.subs, a list is returned where every element corresponds to a base plan or its offer in productDetails.subscriptionOfferDetails.

Implementation

static List<GooglePlayProductDetails> fromProductDetails(
  ProductDetailsWrapper productDetails,
) {
  if (productDetails.productType == ProductType.inapp) {
    return <GooglePlayProductDetails>[
      GooglePlayProductDetails._fromOneTimePurchaseProductDetails(
          productDetails),
    ];
  } else {
    final List<GooglePlayProductDetails> productDetailList =
        <GooglePlayProductDetails>[];
    for (int subscriptionIndex = 0;
        subscriptionIndex < productDetails.subscriptionOfferDetails!.length;
        subscriptionIndex++) {
      productDetailList.add(GooglePlayProductDetails._fromSubscription(
        productDetails,
        subscriptionIndex,
      ));
    }

    return productDetailList;
  }
}