When logout, the database connection is not closed, so it uses the previous users database. Maybe just invalidate the provider or dispose of it.
Simply invalidating it is probably not sufficient. I tried it and drift gave this warning:
flutter: WARNING (drift): It looks like you've created the database class PecuniaDB
multiple times. When these two databases use the same QueryExecutor, race
conditions will occur and might corrupt the database.
Whenever I needed to initialize the database (like in EntryScreen, Login/RegisterScreen, I simply invalidated the provider and watched it again. It seems to work as intended, but may lead to corrupted databases.
Then again, everytime I create a PecuniaDB instance, it most likely uses another database. And whenever a new one comes along, the old one should be inaccessible (courtesy of ref.invalidate).
When logout, the database connection is not closed, so it uses the previous users database. Maybe just invalidate the provider or dispose of it.
Simply invalidating it is probably not sufficient. I tried it and drift gave this warning:
Whenever I needed to initialize the database (like in
EntryScreen
,Login/RegisterScreen
, I simply invalidated the provider and watched it again. It seems to work as intended, but may lead to corrupted databases.Then again, everytime I create a
PecuniaDB
instance, it most likely uses another database. And whenever a new one comes along, the old one should be inaccessible (courtesy ofref.invalidate
).