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 the processing, ideally something like:
Future<Result> = doPayment(
amount: 100.00,
currency: 'USD',
onPasscodeEntry: () => _renderInputBox(),
onValidation: () => _doValidation()
);
the processing itself takes some time etc so a Future<PaymentResult>
pattern makes sense, the application should react to some points of the processing, so it makes sense to pass in callbacks.
Problems:
how to pass functions to Java code? As far as I can tell all the Java-passable method arguments in Flutter are serializable-ish objects
(less critical/optional) how to return a POJO and handle it in Dart? Judging from the specs I should encode (within Java) the result in a
ArrayList
/HashMap
or as aJSON
string and then create the equivalent constructor in Dart that takes inList
/Map
? This seems a bit unwieldy, so I'm asking if there's a simpler way, preferably without maintaining a Java & Dart variants of the same object