1

所以,我想从我的华为开发者帐户中获取我的产品列表,我集成了 sdk,一切都很好。此代码中的问题:

Future<List<ProductInfo>> getConsumableProducts() async {
try {
  ProductInfoReq req = ProductInfoReq(); // The named parameter 'skuIds' is required, but there's no corresponding argument.Try adding the required argument.dartmissing_required_argumentThe named parameter 'priceType' is required, but there's no corresponding argument.Try adding the required argument.dartmissing_required_argument
  req.priceType = IapClient.IN_APP_CONSUMABLE;
  req.skuIds = ["prod_01", "prod_02"];
  ProductInfoResult res = await IapClient.obtainProductInfo(req);
  return res.productInfoList; // A value of type 'List<ProductInfo>?' can't be returned from the method 'getConsumableProducts' because it has a return type of 'Future<List<ProductInfo>>'
} on PlatformException catch (e) {
  log(e.toString());
  return null;
}
}

我提到了代码中的问题。PS:我进行了搜索并验证此代码与公开的代码相同

4

1 回答 1

0

如果您想获取购买信息,您可以按照以下代码:

List<String> productIdList = new ArrayList<>();
// Only those products already configured in AppGallery Connect can be queried.
productIdList.add("ConsumeProduct1001");
ProductInfoReq req = new ProductInfoReq();
// priceType: 0: consumable; 1: non-consumable; 2: subscription
req.setPriceType(0);
req.setProductIds(productIdList);
// Obtain the Activity object that calls the API.
final Activity activity = getActivity();
// Call the obtainProductInfo API to obtain the details of the product configured in AppGallery Connect.
Task<ProductInfoResult> task = Iap.getIapClient(activity).obtainProductInfo(req);

在这里查看更多信息。

于 2021-09-24T02:55:10.080 回答