Flutter – Handling events

If you need to control or monitor the processes that take place on the purchase screen, you need to implement the AdaptyUIObserver methods and register the observer before presenting any screen:


User generated events

Closing the paywall

If the close button is visible and the user presses it, this method will be invoked:

void paywallViewDidPressCloseButton(AdaptyUIView view) => view.dismiss();

// for Android you should also implement system back button press reaction:
void paywallViewDidPerformSystemBackActionOnAndroid(AdaptyUIView view) => view.dismiss();

Product selection

If product was selected for purchase (by user or by system), this method will be invoked.

void paywallViewDidSelectProduct(AdaptyUIView view, AdaptyPaywallProduct product) {

Started purchase

If user initiates the purchase process, this method will be invoked.

void paywallViewDidStartPurchase(AdaptyUIView view, AdaptyPaywallProduct product) {

Canceled purchase

If the user initiates the purchase process but manually interrupts it, this function will be called. Basically, this event occurs when the Adapty.makePurchase() function completes with a .paymentCancelled error:

void paywallViewDidCancelPurchase(AdaptyUIView view, AdaptyPaywallProduct product) {

Successful purchase

If Adapty.makePurchase() succeeds, this method will be invoked:

void paywallViewDidFinishPurchase(AdaptyUIView view, 
                                  AdaptyPaywallProduct product, 
                                  AdaptyProfile profile) {

We recommend to dismiss the screen in that case.

Failed purchase

If Adapty.makePurchase() fails, this method will be invoked:

void paywallViewDidFailPurchase(AdaptyUIView view, 
                                AdaptyPaywallProduct product, 
                                AdaptyError error) {

Successful restore

If Adapty.restorePurchases() succeeds, this method will be invoked:

void paywallViewDidFinishRestore(AdaptyUIView view, AdaptyProfile profile) {

We recommend to dismiss the screen if the user has the required accessLevel.

Failed restore

If Adapty.restorePurchases() fails, this method will be invoked:

void paywallViewDidFailRestore(AdaptyUIView view, AdaptyError error) {

Data fetching and rendering

Products loading errors

If you didn't pass the product array during initialization, AdaptyUI will retrieve the necessary objects from the server by itself. In this case, this operation may fail, and AdaptyUI will report the error by invoking this method:

void paywallViewDidFailLoadingProducts(AdaptyUIView view, AdaptyIOSProductsFetchPolicy? fetchPolicy, AdaptyError error) {

Rendering errors

If an error occurs during the interface rendering, it will be reported by calling this method:

void paywallViewDidFailRendering(AdaptyUIView view, AdaptyError error) {

In a normal situation such errors should not occur, so if you come across one, please let us know about it.