Use of Isolates #3268
-
Hello, I apologize for bothering you but I must be missing something, I can't figure out how to properly use Isolates with Drift. To make it short: I need to access my DB directly and sometimes via Isolates from the WorkManager. Before seeing your section on Isolates, sometimes it worked with my basic implementation, sometimes I had the error message Then I came across your doc. I tried to do this:
Then, at the beginning of my isolate, I do:
But already, I have a warning that is displayed when my isolate opens and I call getIt.init() to retrieve my DB.
I feel like I'm not doing things right but I don't know where, can you help me please? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
What is You also don't have to combine |
Beta Was this translation helpful? Give feedback.
-
Yes sorry for the isolateGetIt, it's a bad replacement for copy-paste, I had tried to create a getIt specific to the isolate.
But the problem is that when I run the task via the WorkManager, I get this error when I want to access the database ...
Ex methods call : TEST 1 : Exception
TEST 2 : Exception
CREATE : Exception
|
Beta Was this translation helpful? Give feedback.
-
No worries, actually I hadn't put the code of the callbackDispatcher of my WorkManager:
The token is therefore created in the WorkManager and not passed to the task |
Beta Was this translation helpful? Give feedback.
Ok, so looking at e.g. this, it appears to be possible to use the platform manager in workmanager tasks. This means that you won't be able to regularly open your drift database from within the work manager task, as
getApplicationDocumentsDirectory()
is simply not available.I think this approach should work:
inputData
.So in the end, it could look like this: