fetchProductItems method

Future<void> fetchProductItems()

Implementation

Future<void> fetchProductItems() async {
  try {
    // Fetch the products items from the store using the products IDs.
    _productItems =
        await FlutterInappPurchase.instance.getProducts(_productIds);

    // Sort the products items in the order of their IDs.
    _productItems.sort((a, b) => _productIds
        .indexOf(a.productId!)
        .compareTo(_productIds.indexOf(b.productId!)));

    if (kDebugMode) {
      print(_productItems);
    }
  } catch (e) {
    // Log an error if fetching products items fails.
    if (kDebugMode) {
      print("Failed to fetch products items: $e");
    }
  }
}