Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: DatabaseException(error database_closed) #745

Open
lumingyuan opened this issue Mar 8, 2023 · 2 comments
Open

Unhandled Exception: DatabaseException(error database_closed) #745

lumingyuan opened this issue Mar 8, 2023 · 2 comments

Comments

@lumingyuan
Copy link

How can I solve the issue where a StreamBuilder refreshes and throws an exception when I try to close the database?

E/flutter ( 4865): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: DatabaseException(error database_closed)
E/flutter ( 4865): #0 SqfliteDatabaseMixin.checkNotClosed
package:sqflite_common/src/database_mixin.dart:337
E/flutter ( 4865): #1 SqfliteDatabaseExecutorMixin._rawQuery
package:sqflite_common/src/database_mixin.dart:124
E/flutter ( 4865): #2 SqfliteDatabaseExecutorMixin.query
package:sqflite_common/src/database_mixin.dart:10

@lumingyuan
Copy link
Author

My requirement is to restore data, so I need to close the database first, then overwrite the database file and reopen it. However, when I use dao.queryStream with StreamBuilder, closing the database will prompt that the database has already been closed. How can I write this logic correctly?

@SEGVeenstra
Copy link
Collaborator

I think you should not directly rely on the Stream in the StreamBuilder. If you use a StreamBuilder directly, I think it will expect to be responsible for the closing, so when you close it yourself, it might continue tryin to read a closed stream.

I think you will have to manage this yourself, depending on your app's architecture, a StatefulWidget might do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants