hive icon indicating copy to clipboard operation
hive copied to clipboard

Clear boxes

Open andresdecba opened this issue 4 years ago • 2 comments

Question Hi guys, what I want to do is delete all the data from the boxes and start saving data again. I did the next method to reset the boxes, but I get this error: "the box has been closed". How could I re-open the boxes once they are closed or how to complete clear boxes and memory ? Thank you very much for your answers : )

Code sample

Future resetBoxes() async {
    // clear
    await usersBOX.clear();
    await expensesBOX.clear();
    // compact
    await usersBOX.compact();
    await expensesBOX.compact();
    // close
    await Hive.close();
    // re open boxes
    await Hive.openBox<UserModel>('USERS-BOX');
    await Hive.openBox<ExpenseModel>('EXPENSE-BOX');
}

Version

  • Platform: Android
  • Flutter version: 2.5
  • Hive version: 2.0.4

andresdecba avatar Nov 23 '21 13:11 andresdecba

Delete the box from entirely. usersBox.deleteFromDisk()

keezysilencer avatar Dec 17 '21 13:12 keezysilencer

@keezysilencer deleteFromDisk() isn't working

Macacoazul01 avatar Jul 22 '22 01:07 Macacoazul01