Home > Software engineering >  How to call this.superClassMethod on Kotlin?
How to call this.superClassMethod on Kotlin?

Time:06-29

I have the following code:

class MainActivity: FlutterActivity() {
    companion object {
        private val STREAM: String = "com.example.my_app/stream";

        private lateinit var EVENT_CHANNEL: EventChannel
        init {

            EVENT_CHANNEL = EventChannel(this.getFlutterEngine().getDartExecutor().getBinaryMessenger(), STREAM)
            

but I get Unresolved reference: getFlutterEngine, but the method exists: https://api.flutter.dev/javadoc/io/flutter/embedding/android/FlutterActivity.html#getFlutterEngine()

I also tried [email protected]() and [email protected](). I think the problem is that things are inside the Companion object.

How to call getFlutterEngine?

CodePudding user response:

this is Pointing MainActivity.companion, not MainActivity, since you're calling inside of companion object

Seems like you are trying to achieve to make EVENT_CAHNNEL that can access from anywhere. You might need to think to change design.

  • Related