Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using the simple code below

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

however it is returning the error

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

I was wondering if anyone knew a reason for this error and if so what should i fo about it, Happy to have any suggestions - thanks.

like image 384
GILO Avatar asked Feb 03 '20 20:02

GILO


1 Answers

The documentation is very thin on this and should actually be more clear. You need include the line below in main() for it to work.

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

  runApp(MyApp());
}
like image 87
GILO Avatar answered Oct 31 '22 10:10

GILO