Flutter messaging classes and their native platform peers

Communication between Flutter modules and Mobile Native code happens over platform channels.  The docs are all over the place so I created this cheat sheet for the different channel types and their class documentation.

YouTube walkthrough video

Mobile Native Communication


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 classDescriptionFlutter
Native
Native
Flutter
Supports
Return
MethodInvoke method on the other sideYesYesVia result
MessageSends a message to a remote listenerYesYesVia reply
EventStreams and sinks. Events can flow in both directionsYesYesN/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 ClassiOS ClassAndroid Class
MethodChannelFlutterMethodChanelMethodChannel
EventChannelFlutterEventChannelEventChannel
BasicMessageChannelFlutterBasicMessageChannelBasicMessageChannel

Method Channel Codecs MethodCodec


Method channels a method on the opposite side.  Method channels use MethodCode implementations.


Flutter Codec ClassiOS Codec ClassAndroid Codec Class
MethodCodec Interface......
StandardMethodCodecFlutterStandardMethodCodecStandardMethodCodec
JSONMethodCodecFlutterJSONMethodCodecJSONMethodCodec

Message Channel Codecs


Message channels use MessageCodec Implementations.  Messages are a single payload with an optional return value. Uses codecs shown below.


Flutter Codec ClassiOS Codec ClassAndroid Codec Class
MessageCodec Interface......
StandardMessageCodecFlutterStandardMessageCodecStandardMessageCodec
BinaryCodecFlutterBinaryMessageCodecBinaryCodec
JsonMessageCodecFlutterJSONMessageCodecJSONMessageCodec
StringCodecFlutterStringCodecStringCodec

Event Channel


Event channels are continuous broadcast streams that use a MethodCodec. Some future blog will describe Event Channels.


Flutter Codec ClassiOS Codec ClassAndroid Codec Class
See MethodCodecSee MethodCodecSee MethodCodec

Platform-specific implementations

Additional details are available for each platform implementation in the sample code in the referenced repository. From README.md in GitHub repository

Platform
Web application with message communication between Flutter and Web
Android application with message communication between Flutter and Android
iOS application with message communication between Flutter and Android

YouTube Video

Revision History

Created 2024 07 - copied from the readme and manually reformatted

Comments

Popular posts from this blog

Installing the RNDIS driver on Windows 11 to use USB Raspberry Pi as network attached

Understanding your WSL2 RAM and swap - Changing the default 50%-25%

Almost PaaS Document Parsing with Tika and AWS Elastic Beanstalk