【发布时间】:2020-06-24 06:04:06
【问题描述】:
我知道我可以通过dart代码访问多个MethodChannel,但是我应该如何在平台代码上实现多个MethodChannel而不使用多个插件。
我已经尝试过搜索,但每个文档和文章都只显示每个插件的单个方法通道
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "org.my.application/channel")
channel.setMethodCallHandler(this);
}
在上述 Flutter 插件的onAttachedToEngine 中,我创建了一个名为“org.my.application/channel”的单个频道,我怎样才能在同一个插件中制作更多内容?
我现在唯一的选择是在多个插件中使用划分不同方法通道的实现。
有没有办法将它们保存在一个插件中?
【问题讨论】:
-
多个
MethodChannels有什么问题?您只需使用不同的String name,就可以拥有任意数量的频道 -
我不知道如何在一个包中创建多个MethodChannel。
-
在调用
MethodChannel构造函数时使用不同的String name -
我可以通过dart端访问多个通道但是如何在不使用多个包的情况下在Platform端实现多个方法通道
-
所以使用
channel1 = MethodChannel(...); channel1.setMethodCallHandler(handler1); channel2 = MethodChannel(...); channel2.setMethodCallHandler(handler2);- 多通道和多处理程序有什么问题?