adaptyteam / AdaptyUI-Flutter

Extension to the Adapty SDK that allows you to easily add purchase screens to your application.
https://docs.adapty.io/docs/paywall-builder-getting-started
MIT License
12 stars 5 forks source link

MissingPluginException When Displaying Adapty UI After App Launch via FCM Push Notification #12

Closed MarklBcm closed 1 week ago

MarklBcm commented 1 month ago

I am encountering an issue where the Adapty UI fails to display with the following error when the app is launched via an FCM push notification: MissingPluginException(No implementation found for method create_view on channel flutter.adapty.com/adapty_ui)

This issue occurs under the following conditions:

  1. The app is terminated.
  2. The app is launched via an FCM push notification.
  3. The user attempts to display the Adapty UI.

Environment: • Adapty SDK Version: 2.10.1 • Adapty UI Version: 2.1.2 • Flutter Version: 3.22.2 • Platform: [Android] • OS Version: [Android 9, Android 10, Android 13(sometimes)]

Additional Context: This error does not occur on all devices, but seems to be specific to certain device models or OS versions. The issue might be related to the timing of Flutter plugin initialization when the app is launched via a notification.

Would appreciate any guidance or a potential fix for this issue. Thank you!

x401om commented 1 month ago

Hey @MarklBcm! It seems like you have to initialize plugin by yourself before accessing its methods. I hope this related issues will help you:

1) https://github.com/firebase/flutterfire/issues/8204 2) https://github.com/flutter/flutter/issues/99155

MarklBcm commented 2 weeks ago

Thanks to your help, I’ve learned something new. However, I still haven’t found a way to resolve the issue.

In my case, the issue also occurs in the release build.

I’d like to report an additional related issue:

When the app is closed using the physical back button on Android and then reopened, the same MissingPluginException occurs. • I temporarily resolved this issue by using exit(0), but I don’t think this is the best solution.

maru-eom commented 1 week ago

I’m experiencing an issue where the CrossplatformUiHelper.init(flutterPluginBinding.applicationContext) method fails, resulting in the MethodChannel not being initialized. This leads to the AdaptyUiFlutterPlugin throwing an exception

maru-eom commented 1 week ago

I modified the code as follows:

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
    val iniailized = CrossplatformUiHelper.init(flutterPluginBinding.applicationContext)
    if (!iniailized) {
        Log.d("AdaptyUiFlutterPlugin", "CrossplatformUiHelper.init failed.")
    }

    channel = MethodChannel(flutterPluginBinding.binaryMessenger, CHANNEL_NAME).also { channel ->
        channel.setMethodCallHandler(this)
    }
    channel?.let { channel -> callHandler.handleUiEvents(channel) }
}

It works well.

Could this change potentially cause any other issues?

x401om commented 1 week ago

@maru-eom In my experience, as long as you have properly initialized the plugin and the channels, there should not be any issues.

It seems like we have the answer to the initial question, so I am going to close the issue.