Wanna make function which will save the information after clicking the buttom (Save)
But Hive gives error…Screen of VS
Error is in this line:
static Box notes = Hive.box(HiveKeys.notesKey);
Exception has occurred.
HiveError (HiveError: The box "notes" is already open and of type Box.)
2
Answers
First of all you can not directly type hive data into a specific model. You need to get data from the box as dynamic and then cast that data to desired type, and the second thing is it seems that you have already opened this box somewhere in your code. It would be nice if you can share the code where you have opened hive box
If you want to store data in list form then please follow below step
main.dart
fileStep 2: make a model class that contains the adapter of the hive
like this – you can pass typeId of your choice
Step 3: run the
build_runner
command so they generate 2 file of model dtoflutter pub run build_runner watch –delete-conflicting-outputs
Step 4: Now open box where you want to store data :
ListHiveCleanEntity putlist = [];
Step 5: getting data into local storage
final list = cleanContactBox.get("subTable")?.cast<HiveCleanEntity>() ?? [];