Seems I'm not able to load embedded objects when loading the parent object from the DB.
Let's say I have the following parent and children classes.
@collection
class Email {
Id? id;
String? title;
List<Recepient> recipients = List.empty(growable: true);
}
@embedded
class Recepient {
String? name;
String? address;
}
If I store it to the Isar database, I can properly see the tree (through Isar Inspector) which includes the embedded objects with all their values. That means the data is properly stored. The problem is when I try to receive an item of that collection: I get the Email properties properly filled, but the recipients list is always empty. Reading through Isar documentation, it mentions that embedded objects should be loaded automatically. But I have never found an example with nested objects being Lists. Can that be the problem?
My problem was the List.empty(growable: true). This constructor creates an empty list, but it does not initialize the list with any data. Isar does not automatically load data into lists that are not initialized. I added a constructor like
and removed the "List.empty(growable: true). That worked.