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

[FEATURE REQUEST] Plugin support #34

Open
deckerst opened this issue Sep 10, 2023 · 5 comments
Open

[FEATURE REQUEST] Plugin support #34

deckerst opened this issue Sep 10, 2023 · 5 comments
Assignees
Labels
integral_isolates_flutter Requires a Flutter specific package

Comments

@deckerst
Copy link

Is your feature request related to a problem? Please describe.
Trying to call a plugin within a spawn isolate fails. This limits use cases for this package.

Describe the solution you'd like
Since 13937 it's possible to pass a root token and call BackgroundIsolateBinaryMessenger.ensureInitialized within the isolate. But it only works for some plugins (those that do dart -> platform messenging, but not platform -> dart messenging). Hopefully this package can do the necessary plumbing so that it works whatever the plugin.

Describe alternatives you've considered
flutter_isolate is another package trying to make isolates nicer, and it supports plugins, but it has its own issues and limitations.

@lohnn
Copy link
Owner

lohnn commented Sep 10, 2023

Hi!

This is definitely something I've intended to look at at some point. I'll have to look at what the overhead for this would be, and what I'd need to do to make integral_isolate still be able to run in a pure Dart environment too.
I'd be more than happy to get feedback on this and discuss my options/potential solutions to be able to bring interop with packages to integral_isolates. ☺️

@lohnn lohnn added the integral_isolates_flutter Requires a Flutter specific package label Oct 8, 2023
@lohnn
Copy link
Owner

lohnn commented Jan 15, 2024

Hello again!

I am sorry for being so slow at investigating this but I've had a lot of stuff on my plate, and to be honest, this feature request was not on top of my list.

I have tried something that seems to work for me, but I also want to check if it will solve it for you too.

If you try calling this piece of code before making any calls to a plugin:

// Define as a top level function or a static function, just as normal
void _initPluginForIsolate(RootIsolateToken rootIsolateToken) {
  BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);
  print('I am init!');
}
...
// Creating the isolate
isolate = StatefulIsolate();
final rootIsolateToken = RootIsolateToken.instance!;
await isolate.compute(_initPluginForIsolate, rootIsolateToken);

Are you able to call the plugins you wish to work then?
I seem to be able to call at least the shared_preferences plugin, but I would love to hear how well this workaround works.

If it works well, I'll try to neatly wrap it in a nice package and do it automatically in Flutter apps.

@lohnn lohnn self-assigned this Jan 15, 2024
@lohnn
Copy link
Owner

lohnn commented Feb 7, 2024

I realise now that I repeated exactly what you said and didn't actually solve your problem 🙈
But I am looking into how to fix this and I'm working on a wrapping package that sets up and allows for this functionality.

@deckerst
Copy link
Author

deckerst commented Feb 7, 2024

Glad you're looking into it. However, to be perfectly candid, when I opened this issue I was investigating something and trying out several isolate related packages, but I can't remember what I was searching then... So I can't really follow up on my initial request or help you push this further.

@lohnn
Copy link
Owner

lohnn commented Feb 7, 2024

I believe I've come to the conclusion that I will need to implement native code for all supported platforms in order to support hooking up native calls to push data to Flutter.
I have decided that I will create the package anyway, but initially only support dart -> native. I will then create a follow up issue in the backlog to try to implement native -> dart.
At least I think that I know how I want the API surface to look when I eventually cross that road.

Thank you for the feature request, it is definitely something that I really want to have eventually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integral_isolates_flutter Requires a Flutter specific package
Projects
None yet
Development

No branches or pull requests

2 participants