Skip to content

Use of Isolates #3268

Answered by simolus3
CharlotteJu asked this question in Q&A
Oct 7, 2024 · 3 comments · 5 replies
Discussion options

You must be logged in to vote

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:

  1. Extract the logic used to find the path for the database into a standalone function.
  2. Use that to open the database on the main isolate.
  3. When registering a work manager task, tell it about the path to the database using inputData.

So in the end, it could look like this:

Future<File> _databaseFile() async {
  final dbFolder = await getApplicationDocumentsDirectory();
  return File(p.join

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@simolus3
Comment options

Comment options

You must be logged in to vote
4 replies
@simolus3
Comment options

@CharlotteJu
Comment options

@simolus3
Comment options

Answer selected by CharlotteJu
@CharlotteJu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants