Flutter in_app_purchase '_enablePendingPurchases':在调用 startConnection 之前必须调用 enablePendingPurchases()

GIL*_*ILO 12 in-app-purchase dart flutter

我正在使用下面的简单代码

bool available = await InAppPurchaseConnection.instance.isAvailable();
Run Code Online (Sandbox Code Playgroud)

但是它正在返回错误

E/flutter (14525): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:'package:in_app_purchase/src/billing_client_wrappers/billing_client_wrapper.dart':断言失败:第 101 行 pos 12:结尾 PurchaensableP ': enablePendingPurchases() 必须在调用 startConnection 之前调用

我想知道是否有人知道这个错误的原因,如果是的话我应该怎么做,很高兴有任何建议 - 谢谢。

GIL*_*ILO 55

文档对此非常薄,实际上应该更清楚。您需要在 main() 中包含以下行才能使其工作。

void main() {
  ///Include this in main() so purchases are enabled
  InAppPurchaseConnection.enablePendingPurchases();

  runApp(MyApp());
}
Run Code Online (Sandbox Code Playgroud)

  • 我同意你的观点,依赖性很棒,但文档很差。很高兴我遇到了这个。 (4认同)