Flutter - PlatformChannel binding methods that returns custom Objects Flutter - PlatformChannel binding methods that returns custom Objects flutter flutter

Flutter - PlatformChannel binding methods that returns custom Objects


The StandardMessageCodec can only send certain types across the boundary. Also, you can't send a Java class across the boundary - what would it turn into at the Dart end?

There are things that you can do:

  1. Serialize the Java object to JSON, transfer the string, then deserialize as a Dart object

  2. Put the Java object's fields into a HashMap (key is a string, value is a supported type), transfer it (will appear as a Map<String, dynamic>) and access the fields.

  3. Write your own codec (or subclass the standard codec) where you end up basically doing (2) but with less overhead of the string field names. (This is tricky...)