原理阐释
Flutter和Native通信是通过Platform Channels来实现的,架构图如下:
图里面连接他们的是MethodChannel,其实MethodChannel是Platform Channels中的一种,顾名思义,MethodChannel用起来应该和方法调用差不多。如果你需要把数据从Native平台发送给Flutter,可以使用EventChannel或者BasicMessageChannel。
-
BasicMessageChannel:用于传递字符串和半结构化的信息
-
MethodChannel:用于传递方法调用(method invocation)
-
EventChannel:用于数据流(event streams)的通信(例如 NSData)
这里需要注意一点,为了保证