Fair icon indicating copy to clipboard operation
Fair copied to clipboard

Plugin部分,js调用dart为什么要传pageName?

Open yx-mike opened this issue 2 years ago • 0 comments

问题

定了Plugin,js和dart都写好,iOS也调通了,但是Android确不行?缺少"pageName"

我看了这部分Java的实现逻辑,pageName的作用主要是,在dart返回之后回调js方法时候指定上下文GLOBAL[pageName],就是指定js方法的this。 但是iOS没有这样的逻辑。

其实我不是很理解,对于公用的Plugin模块,为什么要在invokeFlutterCommonChannel方法返回时候绑定this到pageName, 如果是想回调给pageName,不是可以在调用插件时候传callback function吗。

现在的状况就是,所有Plugin调用都必须加上#FairKey#参数,在Plugin的js代码中又必须通过key“pageName”透传#FairKey#。

其实大部分情况下,Plugin的dart方法都不需要#FairKey#,除非想通过#FairKey#去获取当前dart中的State。

环境信息

flutter doctor --verbose
[✓] Flutter (Channel vd/main, 2.5.1042, on macOS 13.3.1 22E772610a darwin-x64, locale zh-Hans-CN)
    • Flutter version 2.5.1042 at /Users/hxd/Documents/flutter/flutter
    • Upstream repository ssh://[email protected]:60022/flutter/flutter.git
    • Framework revision a8cad5e28c (7 months ago), 2022-10-27 11:59:08 +0800
    • Engine revision b3af521a05
    • Dart version 2.14.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn
dependencies:
  fair: 3.0.0

yx-mike avatar May 19 '23 08:05 yx-mike