Flutter hivebox HiveError: Box has already been closed

Viewed 792

I am using this function to make sure to open and close box appropriately but i am still getting HiveError: Box has already been closed. error

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;
  } 

How can i resolve this issue.

0 Answers
Related