gpt4 book ai didi

flutter - 在flutter插件中获取事件引用

转载 作者:行者123 更新时间:2023-12-03 13:28:36 27 4
gpt4 key购买 nike

当我创建一个flutter插件时,默认情况下,插件类中有两种方法:

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding)


fun registerWith(registrar: Registrar)

文件上的注释说: It is encouraged to share logic between onAttachedToEngine and registerWith to keep them functionally equivalent. Only one of onAttachedToEngine or registerWith will be called depending on the user's project. onAttachedToEngine or registerWith must both be defined in the same class.
现在,我需要使用 activity.startActivityForResult()从此处开始另一个事件。
可以使用 registerWith(registrar: Registrar)registrar.activity()中获得对事件的引用。如何在 onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding)方法中执行此操作?

最佳答案

找到了解决方案here
实现ActivityAware及其方法之一是

 override fun onAttachedToActivity(binding: ActivityPluginBinding) {
this.activity = binding.activity;
}

关于flutter - 在flutter插件中获取事件引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59887901/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com