【问题标题】:Flutter in_app_purchase '_enablePendingPurchases': enablePendingPurchases() must be called before calling startConnectionFlutter in_app_purchase '_enablePendingPurchases':必须在调用 startConnection 之前调用 enablePendingPurchases()
【发布时间】:2020-05-19 15:53:33
【问题描述】:

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

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

但是它返回错误

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 : '_enablePendingPurchases': enablePendingPurchases() 必须在调用 startConnection 之前调用

我想知道是否有人知道此错误的原因,如果知道,我应该对此有何看法,很高兴有任何建议 - 谢谢。

【问题讨论】:

    标签: flutter dart in-app-purchase


    【解决方案1】:

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

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

    【讨论】:

    • 我同意你的观点,依赖性很棒,但文档很差。很高兴我遇到了这个。
    • @Martins 完全同意你的观点
    • 我正在尝试将应用内购买集成到我的应用中。请给我一些您在集成此插件时遵循的参考链接。尽管我的应用程序已发布,但我的产品列表为空。媒体上有一篇关于这个插件的文章,但我没有在媒体上订阅。请帮帮我。
    • @KPradeepKumarReddy pub.dev/packages/in_app_purchase
    【解决方案2】:

    我无法导入 InAppPurchaseConnection 来尝试接受的解决方案,并通过以下方式解决了这个问题:

    import 'package:flutter/foundation.dart';
    import 'package:in_app_purchase_android/in_app_purchase_android.dart';
    
    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      // Inform the plugin that this app supports pending purchases on Android.
      // An error will occur on Android if you access the plugin `instance`
      // without this call.
      if (defaultTargetPlatform == TargetPlatform.android) {
        InAppPurchaseAndroidPlatformAddition.enablePendingPurchases();
      }
      runApp(MyApp());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      相关资源
      最近更新 更多