-
Hi, apologies if this has been answered before, I'm just getting confused seeing all the previous discussions, many of which refer to previous versions. I am using android_alarm_manager_plus to create a background isolate in flutter. What is the recommended way to access the database from that isolate? And would there be any issue if I am trying to write to the database from multiple isolates? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So generally, the best approach is to use So as long as the two isolates share a @DriftDatabase(...)
class AppDatabase extends _$AppDatabase {
AppDatabase() : super(driftDatabase(name: 'app.db', native: DriftNativeOptions(shareAcrossIsolates: true))); Then, regardless of the isolate you open your database in, they'll all talk to the same database instance. A downside is that this is currently broken for isolates in different Flutter engines (see the linked discussion for the workaround until the upcoming drift release).
In this setup, there wouldn't be any issues with that since the Instead of using |
Beta Was this translation helpful? Give feedback.
So generally, the best approach is to use
drift_flutter
for that, similar to what is being done here: #3229So as long as the two isolates share a
IsolateNameServer
instance (I think they do since they're running in the same process), you can use thedriftDatabase
function frompackage:drift_flutter
with theshareAcrossIsolates: true
option) like this:Then, regardless of the isolate you open your database in, they'll all talk to the same database instance. A downside is that this is currently broken for isolates in di…