Я пытаюсь получить доступ к справочнику действий в плагине Flutter, написанном в Kotlin, когда я нажимаю FAB в Flutter.
Мой класс ActivityAware
Вот код : Kotlin:
lateinit var myActivity: Activity
//Method called by ActivityAware plugins to fetch the activity on re-initialization
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
this.myActivity = binding.activity
}
//Method called by ActivityAware plugins to fetch the activity on initialization
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.myActivity = binding.activity
}
//With this method is called from Flutter to check if the Activity is accessible.
//In this case it is always returning null/ not initialized
//It prints "FAILED AGAIN!!"
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "checkForActivity") {
if(::myActivity.isInitialized){
System.out.println("I FOUND IT!!")
}else{
System.out.println("FAILED AGAIN!!")
}
return
} else {
result.notImplemented()
}
}
Код дротика (Флаттер):
//This Flutter class is run whenever you press a button to check for the Activity in Native Kotlin.
static const MethodChannel _channel =
const MethodChannel('sphinx_plugin');
static Future<bool> get checkForActivity async {
final bool isready = await _channel.invokeMethod('checkForActivity');
return isready;
}