Flutter 平台通道调用的两个方向?
Flutter both directions of platform channel call?
根据 flutter platfrom 频道的当前 documentation,似乎只能从客户端 (Dart) 调用主机 (Native),然后我们从主机获得响应。是否有任何相反的可能性,例如从主机直接调用客户端?
是的,这可以使用 MethodChannel
。
您将使用 setMethodCallHandler
在方法通道上指定调用处理程序。
例如,Java version of MethodChannel
has the invokeMethod
方法就像 Dart class 一样。这意味着您可以在所有平台上使用 invokeMethod
。如果您从原生调用它,则必须在 Flutter 中设置一个方法调用处理程序,反之亦然。
在iOS上完全一样。
根据 flutter platfrom 频道的当前 documentation,似乎只能从客户端 (Dart) 调用主机 (Native),然后我们从主机获得响应。是否有任何相反的可能性,例如从主机直接调用客户端?
是的,这可以使用 MethodChannel
。
您将使用 setMethodCallHandler
在方法通道上指定调用处理程序。
例如,Java version of MethodChannel
has the invokeMethod
方法就像 Dart class 一样。这意味着您可以在所有平台上使用 invokeMethod
。如果您从原生调用它,则必须在 Flutter 中设置一个方法调用处理程序,反之亦然。
在iOS上完全一样。