-
Notifications
You must be signed in to change notification settings - Fork 126
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
Store can not be opened from a background service when initialized from main thread, neither I am able to check if the store is open on given location. #699
Comments
I just recently commented about this: #696 (comment) Note: I labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments. |
Tried using attach method inside a background service onStart method and it says,
and If I try to open the store again, It gives can not open store error which I mentioned above. Future<Store> createStore() async {
final docsDir = await getApplicationDocumentsDirectory();
// Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
final st = openStore(directory: p.join(docsDir.path, "obx-example"));
return st;
}
Future<Store> attachStore() async {
// final storeRef = globalStore!.reference;
final docsDir = await getApplicationDocumentsDirectory();
return Store.attach(getObjectBoxModel(), p.join(docsDir.path, "obx-example") );
} I called this create store method in main method and attach store method inside service onStart method. |
Thanks for the details! As it looks like Dart state is shared, maybe I jumped to conclusions and this background service does not actually run in a separate isolate, but the main isolate. In that case, have you tried to make your code access the Store from a global variable and only initialize it in the main method, like in the examples? |
Yes, I have tried using a global variable. assign store to that variable in main method and when access that variable inside service onStart, variable have null value. I can share the complete code in case you need it? |
@Chandio763 Yes, a working code example is always more helpful! Anyhow, I have to look into how this background service package actually works to understand how to fix this. |
Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue. |
Reopening: while a code example is missing, it appears it is still useful to look into this use case. |
I have searched existing issues
Steps to reproduce
### Expected behavior
If I am inside the background service. I should be able to openStore on that location to access data or I can get that opened store to perform operations. I should be able to perform operations on same store from UI thread and background service as well.
Actual behavior:
It throws error stating store is already opened.
Code
Please use example code of flutter background service
Things you maybe should also include:
My pubspec.yaml
Logs
The text was updated successfully, but these errors were encountered: