首页 > 解决方案 > Flutter hivebox HiveError: Box has already been closed

问题描述

我正在使用此功能来确保正确打开和关闭框,但我仍然收到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;
  } 

我该如何解决这个问题。

标签: flutterflutter-hive

解决方案


推荐阅读