0

I want to store List of Hive Object Model2 to a Hive Object Model1

Here is my data Model:

@HiveType(typeId: 0)
class Model1 extends HiveObject {
  @HiveField(0)
  int? id;
  @HiveField(1)
  HiveList<Model2>? list;

  Model1({this.id, this.list});
}

@HiveType(typeId: 1)
class Model2 extends HiveObject {
  @HiveField(0)
  int? id;
  @HiveField(1)
  String? name;

  Model2({this.id, this.name});
}

At first I stored the Model1 with this:

await model1Box.add(Model1(id: counter, list: HiveList<Model2>(model2Box)));

And then I tried this way to store/update this list of Model2 to Model1 :

    var _object = Model2(id: counter, name: 'Name $counter');

    await model2Box.add(_object);

    model1Box.values.last.list!.add(_object);

But this doesn't work.

leftjoin
  • 36,950
  • 8
  • 57
  • 116
Santo Shakil
  • 981
  • 2
  • 13
  • 27

0 Answers0