j0j00 / flutter_liquidcore

Node.js virtual machine for Android and iOS in Flutter.
https://pub.dev/packages/flutter_liquidcore
BSD 2-Clause "Simplified" License
67 stars 16 forks source link

Fix for MicroService @UiThread error introduced in Flutter 1.7 #7

Closed krista-koivisto closed 4 years ago

krista-koivisto commented 4 years ago

This is a fix for issue https://github.com/j0j00/flutter_liquidcore/issues/5 and possibly also https://github.com/j0j00/flutter_liquidcore/issues/1.

Google introduced a new error with commit https://github.com/flutter/engine/commit/2c9e37c34e79475bbde7c8163eb5e56cdb9662a that causes plugins to throw if they are not run on the main thread when marked with @UiThread, which seems to be the problem with #5.

The only proposed fix (see https://github.com/flutter/flutter/issues/34993 thread in particular) for this issue that I could find is to ensure that the method runs on the main thread as requested. This pull request implements said fix.

Even though the invokeMethod calls are now always made on the main thread, the Node.js VM is still run on a separate thread and won't lock up the UI while JavaScript code is being evaluated.

j0j00 commented 4 years ago

Thanks for the research and PR! Much appreciated.