-
Notifications
You must be signed in to change notification settings - Fork 27.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need a way to make synchronous calls from plugin platform code to Dart code #28310
Comments
Hi @amirh, is there any progress on this issue? |
I don't see how the proposal would avoid deadlocks. Wouldn't a deadlock still happen if the dedicated isolate communicated with the main Dart thread which then communicated with the platform thread? |
cc @gaaclarke since this ties in to your https://docs.google.com/document/d/1bD_tiN987fWEPtw7tjXHzqZVg_g9H95IS32Cm609VZ8 explorations (sorry google internal) on pigeon. |
This is already possible with FFI. I have examples of it here for android and iOS: https://github.com/gaaclarke/MessagingTiming |
@iskakaushik just found this bug with some more context. Also, there's some interest in the reverse direction as well. But it doesn't have to be the same technical solution. An example is ByteDance wanting to consult a native SDK API while building a frame without incurring the thread hopping expenses. But I'd treat that direction at a lower priority. |
The same limitation we are also facing when we are trying to share data via content provider from flutter app to a different native app. Please find the scenario below.
If anyone can think of any workaround, please jump in. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
It would be very good to have synchronous way of communicating with native platforms, and not only from plugins. I can give some examples for both directions: from flutter to iOS
from iOS to flutter
what i want to say is most of time there is some kind of workaround possible, but it requires unnecessary extra work for things which are already existing. |
This came up as part of #25329:
The Android WebView API allows passing in a delegate that is invoked on the platform thread before a page is about to be loaded, the delegate needs to synchronously return true or false to determine whether to allow the navigation or to block it.
We needed to expose the same functionality in the webview_flutter plugin, ideally by delegating the decision to the Flutter application's Dart code. But this is currently impossible due to the combination of:
Even if we were to block the platform thread waiting for the Dart code to make a decision, we would not be able to receive the message back from Dart(as the platform thread is blocked) and create a deadlock.
One potential approach for overriding this is to allow "platform channels" that deliver message to platform code on a separate thread. We could then:
If we do this we should probably require that the "special thread" is always different from the platform thread.
For #25329 we're currently proceeding with a workaround that makes some security compromises(which means when an app sets a navigation delegate it should only load trusted content). But we should remove that workaround as soon as this issue is resolved.
cc @cbracken @jason-simmons
The text was updated successfully, but these errors were encountered: