Skip to main content
Solved

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

  • February 24, 2024
  • 1 reply
  • 880 views

Forum|alt.badge.img+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

Best answer by toni-rico

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!

View original
Did this post help you find an answer to your question?
This post has been closed for comments

1 reply

Forum|alt.badge.img+3
  • RevenueCat Staff
  • 58 replies
  • Answer
  • February 26, 2024

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!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings