-
In my app, I need to insert some default values into the db when the db is created. I am currently doing it by using onCreate on MigrationStrategy so that the defaults are always extracted from json and inserted whenever the db is created. Due to the size of the json that needs to be serialized I need to run it on a separate isolate because it's causing issues on the UI thread. I've tried using computeWithDatabase but I keep getting an error about illegal argument in isolate message. Please can anyone suggest alternative simple ways of doing things? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If you post some more details about your approach and what the illegal argument actually was (recent Dart versions show which field was the problem), it would be easier to help. An alternative way may be to simply use an existing database: If the default values are the same for each user (and not loaded from a backend dynamically), you can create an asset containing an initialized database that already has the values in it. You can write a standalone Dart script (not part of your app) that uses your database class to insert the values once into a database file via But if you're using |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your reply @simolus3 but I have already solved the issue. I later found out that I was trying to write to the instance of the database on the "main thread" instead of the one that was created by the new isolate. To help anyone who might make the same mistake I made, this is the code snippet that was causing the error:
It was fixed by;
The difference is that in the code snippet where the code runs without issues, the table instances are gotten from the database provided in the callback. |
Beta Was this translation helpful? Give feedback.
Thank you so much for your reply @simolus3 but I have already solved the issue. I later found out that I was trying to write to the instance of the database on the "main thread" instead of the one that was created by the new isolate. To help anyone who might make the same mistake I made, this is the code snippet that was causing the error: