Solved

How to use Paywall in Flutter? (Android part in kotlin)

  • 24 February 2024
  • 1 reply
  • 195 views

Badge +1

Hi, i have a flutter app and want to include the new paywall feature, but i get error messages, i cant make it work. (Currently i can only test for android, if thats important)

 

If i leave my MainActivity.kt (the main activity for android is in kotlin, not java!) at:

class MainActivity : FlutterActivity() { }

I get the error: 

Unhandled Exception: PlatformException(0, Make sure your MainActivity inherits from FlutterFragmentActivity, null, null)

when i click the button that has this onTap:

onTap: () async {  await RevenueCatUI.presentPaywall();},

 

But if i change it to:

package com.mypackage

import io.flutter.embedding.android.FlutterActivity
import com.revenuecat.purchases_flutter.FlutterFragmentActivity

class MainActivity : FlutterFragmentActivity() {
}

like the documents and community suggests, it gets Unresolved reference: FlutterFragmentActivity

and the app doesnt even start.

 

What should i do to solve this problem? Kotlin seems to be the standard way for Android in Flutter, and i dont think i can change it… 

 

Thanks and best wishes, Janne

icon

Best answer by toni-rico 26 February 2024, 09:52

View original

This post has been closed for comments

1 reply

Userlevel 2
Badge +3

Hi @me-3c8b4f!

The import for `FlutterFragmentActivity` comes from Flutter, not RevenueCat. The import you need to use is

import io.flutter.embedding.android.FlutterFragmentActivity

Lmk if that still doesn’t work and I would be happy to help!