Skip to content
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

Interact with app when running in foreground? #449

Closed
iazel opened this issue Dec 9, 2022 · 5 comments
Closed

Interact with app when running in foreground? #449

iazel opened this issue Dec 9, 2022 · 5 comments

Comments

@iazel
Copy link

iazel commented Dec 9, 2022

Hello,

as per title, is there any way to exchange data between the worker isolate and the app main thread when the latter is running in the foreground?

@bakua
Copy link

bakua commented Dec 24, 2022

Hi, you could have a look at cross isolate communication https://dart.dev/guides/language/concurrency#sending-multiple-messages-between-isolates

@iazel
Copy link
Author

iazel commented Dec 24, 2022

Hi, you could have a look at cross isolate communication https://dart.dev/guides/language/concurrency#sending-multiple-messages-between-isolates

Hi, thanks for the recommendation but I've already looked into it.

The issue here is that we spawn the isolate on the native side and the flutter app is completely ignorant of it. As far as I can see, there is no way to send a Port to it, hence the problem.

@Hamza5
Copy link

Hamza5 commented Feb 24, 2023

Hi, you could have a look at cross isolate communication https://dart.dev/guides/language/concurrency#sending-multiple-messages-between-isolates

Hi, thanks for the recommendation but I've already looked into it.

The issue here is that we spawn the isolate on the native side and the flutter app is completely ignorant of it. As far as I can see, there is no way to send a Port to it, hence the problem.

There is actually a way, using IsolateNameServer from dart:ui.
From the main isolate you should use IsolateNameServer.registerPortWithName(SendPort port, String name) to register the port, then from the work isolate you should use IsolateNameServer.lookupPortByName(String name) to get that port and send messages through it.
I am using this on Android and it is working.

@iazel
Copy link
Author

iazel commented Feb 24, 2023

There is actually a way, using IsolateNameServer from dart:ui. From the main isolate you should use IsolateNameServer.registerPortWithName(SendPort port, String name) to register the port, then from the work isolate you should use IsolateNameServer.lookupPortByName(String name) to get that port and send messages through it. I am using this on Android and it is working.

Oh, didn't know that, thanks for sharing! I wonder why this is in dart:ui instead of dart:isolate, quite puzzling.

@luis901101
Copy link

Duplicate of #151

@ened ened closed this as completed Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants