Present flows in Observer mode in Flutter SDK

If you use Observer mode, you are responsible for your own purchase logic. But you can delegate the paywall UI to the Flow & Paywall Builder.

Design the screen in the builder, and the Adapty SDK renders it natively. Update its copy, layout, and pricing whenever you want, without an app release.

This guide shows how to present a flow and handle the purchase callbacks. If Adapty completes purchases for you, see Display flows & paywalls instead.

Before you start

You need:

Implementation

In Observer mode, the SDK does not make purchases for you. When a user taps the purchase or restore button in an Adapty-rendered flow, the SDK calls your AdaptyUIObserverModeResolver instead — perform the purchase or restore with your own code there.

  1. Implement the AdaptyUIObserverModeResolver:

    class MyObserverModeResolver extends AdaptyUIObserverModeResolver {
      @override
      void observerModeDidInitiatePurchase(
        AdaptyUIFlowView view,
        AdaptyPaywallProduct product,
        void Function() onStartPurchase,
        void Function() onFinishPurchase,
      ) {
        onStartPurchase(); // the view shows its loading indicator
        // make the purchase with your own code, then:
        onFinishPurchase(); // the view hides the loading indicator
      }
    
      @override
      void observerModeDidInitiateRestore(
        AdaptyUIFlowView view,
        void Function() onStartRestore,
        void Function() onFinishRestore,
      ) {
        onStartRestore();
        // restore purchases with your own code, then:
        onFinishRestore();
      }
    }

    The observerModeDidInitiatePurchase method informs you that the user has initiated a purchase, and observerModeDidInitiateRestore — that the user has initiated a restore. Trigger your custom purchase or restore flow in response.

    Also, remember to invoke the following callbacks to notify AdaptyUI about the process of the purchase or restore. This is necessary for proper flow behavior, such as showing the loader, among other things:

    CallbackDescription
    onStartPurchase()The callback should be invoked to notify AdaptyUI that the purchase is started.
    onFinishPurchase()The callback should be invoked to notify AdaptyUI that the purchase is finished.
    onStartRestore()The callback should be invoked to notify AdaptyUI that the restore is started.
    onFinishRestore()The callback should be invoked to notify AdaptyUI that the restore is finished.
  2. Register the resolver before presenting any screen:

    AdaptyUI().setObserverModeResolver(MyObserverModeResolver());
  3. Create and present the flow view as usual: fetch the flow and create its view, then present it. No extra parameters are needed — once the resolver is registered, every Adapty-rendered flow routes purchases and restores through it.

Warning

Don’t forget to report the transaction and associate it with the paywall. Otherwise, Adapty will not recognize the transaction and will not determine the source paywall of the purchase.