FlutterPlugin onAttachedToEngine or registerWith is not getting called

Viewed 431

I have some initialization in onAttachedToEngine or registerWith method. which is not getting called.

As per this link, I am going complete load of the app every time.

And because of this getting an error lateinit property context has not been initialized

private lateinit var channel : MethodChannel

private lateinit var context: Context
private lateinit var activity: Activity

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
    Log.d("***MsalFlutter***", "onAttachedToEngine")
    channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "msal_flutter")
    channel.setMethodCallHandler(this);
    context = flutterPluginBinding.applicationContext
}

companion object {
    lateinit var mainActivity : Activity
    var msalApp: IMultipleAccountPublicClientApplication? = null


    @JvmStatic
    fun registerWith(registrar: Registrar) {
        Log.d("MsalFlutter","Registering plugin")
        val channel = MethodChannel(registrar.messenger(), "msal_flutter")
        channel.setMethodCallHandler(MsalFlutterPlugin())
        mainActivity = registrar.activity()
    }}

Fetting the error message:

kotlin.UninitializedPropertyAccessException: lateinit property context has not been initialized
0 Answers
Related