Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdaptyUIError.viewAlreadyPresented when reopening paywall after closing with back button #15

Open
rignaneseleo opened this issue Oct 26, 2024 · 0 comments

Comments

@rignaneseleo
Copy link

rignaneseleo commented Oct 26, 2024

Description:

Hi, I’m encountering an issue when attempting to reopen the Adapty paywall after it has been closed.

Current Setup

I’ve implemented a singleton to handle the Adapty API as follows:

AdaptyApi(this.ref) {
    try {
        Log.info("Activating Adapty...");
        _adapty = Adapty();
        _adapty.activate();
        _adapty.didUpdateProfileStream.listen(
          (profile) {
              Log.info("Adapty profile updated: $profile");
              ref.read(premiumNotifierProvider.notifier).refresh();
          },
          onError: (error) {
              Log.error("Adapty profile updated error: $error");
          },
          onDone: () {
              Log.info("Adapty profile updated done");
          },
        );
        _adapty.getProfile().then(
            (profile) => FlutterBugfender.setDeviceString(
              "user.adapty_id",
              profile.profileId,
            ),
        );
    } on AdaptyError catch (adaptyError) {
        Log.error(
          "Adapty activation error: ${adaptyError.code} ${adaptyError.message}",
        );
    } catch (error) {
        Log.error("Unexpected error during Adapty activation: $error");
    }
}

late final Adapty _adapty;

The singleton is kept alive by a simple Riverpod provider:

@Riverpod(keepAlive: true)
AdaptyApi adaptyApi(AdaptyApiRef ref) {
    return AdaptyApi(ref);
}

When I need to show the paywall, I instantiate AdaptyUI, fetch the paywall using _adapty.getPaywall(), and then present it.

Problem

If I trigger the paywall again after closing it, I receive the following error: AdaptyUIError.viewAlreadyPresented. This issue appears particularly when closing the paywall using the back button on Android.

Question

What’s the best way to prevent AdaptyUIError.viewAlreadyPresented from occurring when reopening the paywall after closing it? Do I have to run _adapty.activate(); every time?

Additional Context

  • I'm using the back button to dismiss the paywall on Android, which may not be releasing the view as expected.

Any guidance on handling this error or safely resetting the paywall state would be appreciated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant