Flutter Plugin onInit not Initialized


#1

I am trying to develop a TTS plugin, but I am unable to get the onInit method to initialize.

What am I missing?

package com.nannex.fpnew

import android.app.Activity
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import java.util.Locale;
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.PluginRegistry.Registrar


class FpNewPlugin(private var registrar: Registrar, private var activity: Activity): MethodCallHandler, Activity(), TextToSpeech.OnInitListener {


    private var tts: TextToSpeech? = null;
    private var test: String = "init";


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        test = "start";
        tts = TextToSpeech(registrar.context(), this);
        speakOut();
    }


    override fun onMethodCall(call: MethodCall, result: Result): Unit {
        if (call.method.equals("getPlatformVersion")) {
            result.success("Android ${test}")
        } else {
            result.notImplemented()
        }
    }


    override fun onInit(status: Int){
        test = "before if"
        if(status != TextToSpeech.ERROR ){
            test = "hello";
        }


    }
    private fun speakOut() {
        //val text = editText!!.text.toString()
        tts!!.speak("test", TextToSpeech.QUEUE_FLUSH, null,"")
    }


    companion object {
        @JvmStatic
        fun registerWith(registrar: Registrar): Unit {
            val channel = MethodChannel(registrar.messenger(), "fp_new")
            channel.setMethodCallHandler(FpNewPlugin(registrar, registrar.activity()))


        }
    }
}