Flutter messaging classes and their native platform peers
Communication between the Mobile native code and Flutter happens over platform channels. Web communication happens via window messaging.
Flutter Channel types
There are three native platform channel types. V1 of this application uses the Message Channel
Channel type and Flutter class | Description | Flutter Native | Native Flutter | Supports Return |
---|---|---|---|---|
Method | Invoke method on the other side | Yes | Yes | Via result |
Message | Sends a message to a remote listener | Yes | Yes | Via reply |
Event | Streams and sinks. Events can flow in both directions | Yes | Yes | N/A |
Channel Implementation Classes
Dart/Flutter, Android, and iOS have corresponding `channel` classes for each channel type. The three platform channel implementation classes in Flutter, iOS and, Android are:
Flutter Class | iOS Class | Android Class |
---|---|---|
MethodChannel | FlutterMethodChanel | MethodChannel |
EventChannel | FlutterEventChannel | EventChannel |
BasicMessageChannel | FlutterBasicMessageChannel | BasicMessageChannel |
Method Channel Codecs MethodCodec
Method channels a method on the opposite side. Method channels use MethodCode implementations.
Flutter Codec Class | iOS Codec Class | Android Codec Class |
---|---|---|
MethodCodec Interface | ... | ... |
StandardMethodCodec | FlutterStandardMethodCodec | StandardMethodCodec |
JSONMethodCodec | FlutterJSONMethodCodec | JSONMethodCodec |
Message Channel Codecs
Message channels use MessageCodec Implementations. Messages are a single payload with an optional return value. Uses codecs shown below.
Flutter Codec Class | iOS Codec Class | Android Codec Class |
---|---|---|
MessageCodec Interface | ... | ... |
StandardMessageCodec | FlutterStandardMessageCodec | StandardMessageCodec |
BinaryCodec | FlutterBinaryMessageCodec | BinaryCodec |
JsonMessageCodec | FlutterJSONMessageCodec | JSONMessageCodec |
StringCodec | FlutterStringCodec | StringCodec |
Event Channel
Event channels are continuous broadcast streams that use a MethodCodec
. Some future blog will describe Event Channels.
Flutter Codec Class | iOS Codec Class | Android Codec Class |
---|---|---|
See MethodCodec | See MethodCodec | See MethodCodec |
Additional details are available for each platform implementation in the sample code in the referenced repository. From README.md in GitHub repository
Comments
Post a Comment