skip to Main Content

When user clicks on the purchase button, I want to change _isLoading variable to true. Once purchase dialog will appear (on Android or iOS), then set _isLoading back to false.

For simplification, the flow I want:

  1. User clicks on the purchase button (_isLoading is true)
  2. Purchase dialog appears
  3. _isLoading is false

I tried to do like this:

setState(() => _isLoading = true);
await _iap.buyConsumable(
  purchaseParam: PurchaseParam(productDetails: product),
);
setState(() => _isLoading = false);

But on iOS, the _isLoading immediately goes to false when user clicks.

2

Answers


  1. you have to listen the purchase lifecycle. IAP using streamer not async await

    Login or Signup to reply.
  2. You can try with catch() and try() (exception handling)

    try {
      await _iap.buyConsumable(
        purchaseParam: PurchaseParam(productDetails: product),
      );
    } catch (error) {
     //here you can print the occured error
    }
    setState(() => _isLoading = false);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search