I'm writing a flutter app and i need to serialise a class to json. The class is :
@HiveType(typeId: 0)
@JsonSerializable()
class CartItem extends HiveObject {
@HiveField(1)
String item_id;
@HiveField(2)
String name;
@HiveField(3)
SelectionsList selections;
@HiveField(4)
String special_instructions;
@HiveField(5)
int quantity;
@HiveField(6)
double amount;
@HiveField(7)
@JsonKey(ignore: true)
MenuItem item;
CartItem(this.item_id, this.name, this.selections, this.quantity, this.special_instructions, this.amount, this.item);
}
however, due to the item
field being ignored (intended), when i try to generate the .g.dart file, this error is thrown. Cannot populate the required constructor argument: item. It is assigned to an ignored field.
I still need it to be in the constructor though, So is there a workaround for this?