Oh, and I have tried the samples, they kinda work, I just couldn't find the missing piece.
... so it seems my actual problem lies in implementing the setJSONObjectReceivedCallback(). It causes the app to break, without it I am just told that I should
Use architectView.addArchitectJavaScriptInterfaceListener to receive the data.
... which is what I want to do with this:
this.architectWidget.setJSONObjectReceivedCallback(pleaseWork);
Fast forward 10 minutes.
Apparently I put the setJSONObjectReceivedCallback() in a async method, causing it to break the app.
However, now I am setting it in the initState().
I am still told:
forwardJSONObject: There are no ArchitectJavaScriptInterfaceListener set. Use architectView.addArchitectJavaScriptInterfaceListener to receive the data.
Can you give me an example of a correct implementation of that?
Thanks ind advance!
Hello,
I have found the implementation in Flutter that you provided, where the
Future<void> onJSONObjectReceived(Map<String, dynamic> jsonObject) async
is marked as async.
That once again results in the exception I posted initially.
Would you check this behaviour?
Thanks!
I've the same problem on Android, I set the callback in onArchitectWidgetCreated function
Future<void> onArchitectWidgetCreated() async { this.architectWidget .load("samples/01_ImageTracking_1_ImageOnTarget/index.html", () { print("ar works"); }, (string) { print(string); }); this.architectWidget.setJSONObjectReceivedCallback((jsonObjectReceived) { print(jsonObjectReceived.toString()); }); this.architectWidget.resume(); }
The error is always
java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: JsWorker E/AndroidRuntime(15716): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:794)
I think the problem is related to incorrect thread management in the flutter plugin Android implementation.
The problem is probably similar to the one in this post https://github.com/flutter/flutter/issues/34993
Being able to communicate with the rest of the flutter application is essential for the development of a non-demo app.
I hope that those who developed it will find the solution
I'm getting this issue too.
Solved it. In ArchitectWidget.java:
import android.os.Handler;
import android.os.Looper;
@Override
public void onJSONObjectReceived(final JSONObject jsonObject) {
final Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
channel.invokeMethod("jsonObjectReceived", jsonObject.toString());
}
});
}
Great Matthew!
thank you very much!
Hendrik Lakaemper
That breaks the app immediately with the following error message:
What I want to achieve is, when the user clicks on let's say a point of interest, to send a JSON object to flutter, which then does some stuff with it...
Thanks in advance!