How to pass functions as arguments from Dart/Flutter to Android native code?

前端 未结 1 797
傲寒
傲寒 2021-01-22 20:27

I\'d like to create a Java-based SDK that can be invoked from Flutter, the Flutter side needs to plug into the SDK by providing callbacks to be executed at different stages of t

1条回答
  •  囚心锁ツ
    2021-01-22 21:25

    You can not pass a function.

    You can create a map from a function name to a function reference and then pass the function name and look up the function in by name in the map and call it.

    You also can't pass a POJO.

    You need to serialize it to JSON (or some other supported format) and deserialize it on the other side of the channel. For that you need to have to POJO class implemented in Dart and in Java.

    Packages like protobuf or flatbuffer allow to geneerate code for different languages based on an reduced language to specify the data structure.

    0 讨论(0)
提交回复
热议问题