Storing Child objects in box of Parent class.
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
Can you use a box to store different child classes in the same box with all the child data included?
**Code sample**
`class Pet {
String name;
}
class Dog {
bool waggingTail;
}
class Cat {
String coloring = "Black";
}
var box = Hive.openBox('pets');
box.put('doggy', Dog(name="Spot", waggingTail=true));
Dog dog = box.get('doggy');
print(dog.waggingTail);
`
For example using the code above. Can you have a box store Pet and then load a dog or cat and get the data from the child classes, sort of like in the code above (I know the syntax there is probably bad). How to you annotate an arrangement like this? Does Hive automatically store the types (Dog, Cat, Pet) or would you want to add an identifier to the Pet class (eg a String that says whether the object is a Dog or Cat)?
I didn't see anything in the documentation for this configuration and I need to understand this to setup my project appropriately. Thanks for the help.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.