startConnection method

Future<BillingResultWrapper> startConnection({
  1. required OnBillingServiceDisconnected onBillingServiceDisconnected,
  2. BillingChoiceMode billingChoiceMode = BillingChoiceMode.playBillingOnly,
  3. PendingPurchasesParamsWrapper? pendingPurchasesParams,
})

Calls BillingClient#startConnection(BillingClientStateListener) to create and connect a BillingClient instance.

onBillingServiceConnected has been converted from a callback parameter to the Future result returned by this function. This returns the BillingClient.BillingResultWrapper describing the connection result.

This triggers the creation of a new BillingClient instance in Java if one doesn't already exist.

Implementation

Future<BillingResultWrapper> startConnection({
  required OnBillingServiceDisconnected onBillingServiceDisconnected,
  BillingChoiceMode billingChoiceMode = BillingChoiceMode.playBillingOnly,
  PendingPurchasesParamsWrapper? pendingPurchasesParams,
}) async {
  hostCallbackHandler.disconnectCallbacks.add(onBillingServiceDisconnected);
  return resultWrapperFromPlatform(
    await _hostApi.startConnection(
      hostCallbackHandler.disconnectCallbacks.length - 1,
      platformBillingChoiceMode(billingChoiceMode),
      switch (pendingPurchasesParams) {
        final PendingPurchasesParamsWrapper params =>
          pendingPurchasesParamsFromWrapper(params),
        null => PlatformPendingPurchasesParams(enablePrepaidPlans: false)
      },
    ),
  );
}