Bil*_*bbi 10 flutter flutter-hive
我正在使用此功能来确保正确打开和关闭盒子,但我仍然收到HiveError: Box has already been closed.错误
static Future<Box<dynamic>> openIt() async {
var connectionBox = await Hive.openBox(hiveBox);
if (Hive.isBoxOpen(hiveBox) == false) {
await Hive.openBox(hiveBox);
} else {
await connectionBox.close();
connectionBox = await Hive.openBox(hiveBox);
}
return connectionBox;
}
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题。
我真的不知道为什么,但是使用不带 static 关键字的方法并运行它为我修复了它。
static Future<Box<dynamic>> openIt() async { // no
Future<Box<dynamic>> openIt() async { // yes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2228 次 |
| 最近记录: |