0

I am having 2 adapters. I have registered both adapters in main method. I am having only 1 box because database is only one, inside that tables can be multiple.

So I am not able to open same box with different adapter in hive in flutter.

eg :

 Hive.openBox<Adapter1>(box1);
 
 Hive.openBox<Adapter2>(box1);

I want to do this stuff.

padaleiana
  • 955
  • 1
  • 14
  • 23

1 Answers1

1

The adapter for a box describes it's schema, and determines what types of object can be stored in that particular box. Typically you will create (or more likely generate using build_runner package) custom adapters for the custom objects in your app. For this reason it makes no sense to register multiple adapters for one box. If you look into the generated code for these adapters which is actually quite simple, it will provide clarity as to why this isn't possible. If you have different classes in your app which you want to persist using Hive, you will have to setup a new box (and register the relevant adapter) for each class.

Guy McLean
  • 103
  • 8