flutter in_app_purchase '_enablePendingPurchases' : enablePendingPurchases() must be called before calling startConnection

标签 flutter dart in-app-purchase

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

bool available = await InAppPurchaseConnection.instance.isAvailable();

但是它正在返回错误

E/flutter (14525): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: 'package:in_app_purchase/src/billing_client_wrappers/billing_client_wrapper.dart': Failed assertion: line 101 pos 12: '_enablePendingPurchases': enablePendingPurchases() must be called before calling startConnection



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

最佳答案

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

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

  runApp(MyApp());
}

关于 flutter in_app_purchase '_enablePendingPurchases' : enablePendingPurchases() must be called before calling startConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60046903/

相关文章:

flutter - 如果使用 sliver app bar 如何设置状态栏颜色

android - 如何自定义Flutter中 ListView 的各个界面?

Swift IAP 本地化价格

dart - flutter 中的透明底部导航栏

iphone - iOS 7 Beta - 应用内测试不起作用

in-app-purchase - Windows Phone 应用内产品购买的到期日期?

android - 将 map_view 添加到我的 flutter 应用程序不成功

android - 如何在flutter中向用户请求多个权限?

dart - 如何使用传感器 flutter 包开发计步器?

flutter - 为什么在flutter中使用provider时不执行class的构造函数?