isar / hive

Lightweight and blazing fast key-value database written in pure Dart.
Apache License 2.0
4.07k stars 404 forks source link

Hive clear() function does not work as expected. It clears new values added after the .clear() command. #466

Closed rpriyanshu9 closed 2 years ago

rpriyanshu9 commented 4 years ago

Question After adding all the values inside _noteBox, when I try to print them, it shows me that box is empty.

Code sample

 List<Note> noteList = _noteBox.values.cast<Note>().toList();  //storing list of all values in box named _noteBox
_noteBox..clear();                        // clearing the box
noteList.insert(0, newNote);       // insert new element at starting of noteList
_noteBox.addAll(noteList);         // putting old+ 1 new value in the box

Version

themisir commented 4 years ago

You have to await box.clear(). Otherwise clear will be called after all next lines were executed.