queryProductDetails method

  1. @override
Future<ProductDetailsResponse> queryProductDetails(
  1. Set<String> identifiers
)

Query the product detail list.

This method only returns ProductDetailsResponse. To get detailed Store Kit product list, use SkProductResponseWrapper.startProductRequest to get the SKProductResponseWrapper.

Implementation

@override
Future<ProductDetailsResponse> queryProductDetails(
    Set<String> identifiers) async {
  final SKRequestMaker requestMaker = SKRequestMaker();
  SkProductResponseWrapper response;
  PlatformException? exception;
  try {
    response = await requestMaker.startProductRequest(identifiers.toList());
  } on PlatformException catch (e) {
    exception = e;
    response = SkProductResponseWrapper(
        products: const <SKProductWrapper>[],
        invalidProductIdentifiers: identifiers.toList());
  }
  List<AppStoreProductDetails> productDetails = <AppStoreProductDetails>[];
  productDetails = response.products
      .map((SKProductWrapper productWrapper) =>
          AppStoreProductDetails.fromSKProduct(productWrapper))
      .toList();
  List<String> invalidIdentifiers = response.invalidProductIdentifiers;
  if (productDetails.isEmpty) {
    invalidIdentifiers = identifiers.toList();
  }
  final ProductDetailsResponse productDetailsResponse =
      ProductDetailsResponse(
    productDetails: productDetails,
    notFoundIDs: invalidIdentifiers,
    error: exception == null
        ? null
        : IAPError(
            source: kIAPSource,
            code: exception.code,
            message: exception.message ?? '',
            details: exception.details),
  );
  return productDetailsResponse;
}