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

Is there any way to access database in a new isolate? #684

Closed
CalsRanna opened this issue Aug 4, 2022 · 2 comments
Closed

Is there any way to access database in a new isolate? #684

CalsRanna opened this issue Aug 4, 2022 · 2 comments
Assignees

Comments

@CalsRanna
Copy link

Seems like floor does not provide a way to do that. And since I try to use dao to access data from table, it gives me a exception like this below:

FlutterError (Binding has not yet been initialized.
The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized.
Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will return the binding.
In a test, one can call "TestWidgetsFlutterBinding.ensureInitialized()" as the first line in the test's "main()" method to initialize the binding.
If ServicesBinding is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, but that mixes in the selected binding, and that is the class that must be constructed before using the "instance" getter.)

But WidgetsFlutterBinding.ensureInitialized() can only called in root isolate, so I don't know how to do.

@dkaera
Copy link
Collaborator

dkaera commented Sep 14, 2022

@CalsRanna that's true
To do this, you need to implement your own interface that wraps the communication between isolate and UI. Project Drift provides a good explanation of how the interaction with isolate is integrated there.
Floor doesn't provide it as feature, but pay your attention to that you can win with UI performance, but data access is going to be slightly slower because of the isolate data communication bridge. So probably it will be better to focus on the profiling of the DB operations count.

@dkaera dkaera self-assigned this Sep 14, 2022
@dkaera
Copy link
Collaborator

dkaera commented Feb 13, 2023

closed as answered

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

No branches or pull requests

2 participants