DART代码无法在Flutter插件中找到平台实现
我创建了Flutter插件。但是我还需要添加更多渠道。因此,我同时创建了DART代码和本机实现。问题在于,飞镖代码无法找到本机实现,因此它散发出消息“未手持例外:缺少pluginexception(未找到方法...)”,
我将我的本机实现与样品板实现进行了比较,我不喜欢t看到任何错误。我有正确的频道名称。我已经注册了频道。我的频道名称当然与Builderplate实现的频道名称不同。但它与飞镖代码中的一个相匹配。
我想知道,即使我代表不同的功能块,我是否需要所有本机实现都具有相同的频道名称?
I created Flutter plugin. But I also need to add more channels. So I created both dart code and the native implementation. The problem is that the dart code cannot find the native implementation, so it throw out error with the message "Unhandled exception: MissingPluginException (No implementation found for method ...)"
I compared my native implementation with the boilerplate implementation, I don't see anything wrong. I have the correct channel name. I have registered the channel. My channel name is certainly different from the builderplate implementation's channel name. But it matches the one in dart code.
I wonder if I need to have all my native implementations to have the same channel name even though they represent different functionality blocks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为插件创建多个方法渠道,并为每个方法频道分配一个单独的MethodCallHandler。这样,如果在不同的频道中,您可以处理两种具有相同名称的方法。
这是我如何更改“颤动插件”模板以支持多个方法通道的方式。
PS:我使用了Flutter 2.10.5插件模板,因为它更容易理解。在Flutter 3中,他们在飞镖侧添加了一个接口。
飞镖:
kotlin:
swift:
完成源代码: https://github.com/colinschmale/example_plugin
You can create multiple MethodChannels for your plugin and assign an individual MethodCallHandler to each MethodChannel. That way you can handle two methods with the same name differently if they are in different channels.
Here is how I've changed the Flutter plugin template to support multiple MethodChannels.
P.S.: I've used the Flutter 2.10.5 plugin template because it's a bit easier to understand. In Flutter 3 they've added an interface on the Dart side.
Dart:
Kotlin:
Swift:
Complete source code: https://github.com/ColinSchmale/example_plugin