hive
hive copied to clipboard
define fromJson ,fromMap with key
When my class is extending HiveObject I have access to key using the getter defined in HiveObject but after sending the class instance through the network as json I need to convert it back to a model using Model.fromMap(Map<String,dynamic> map) but I can't set the key since it is private and the HiveObjectMixin is not defining a setter
class User extends HiveObject {
final String name;
User({required this.name});
factory User.fromMap(Map<String, dynamic> map) {
return User(
name: map['name'], // <<here I need to set key as well but I can't
);
}
}
How can I define a fromMap factory that returns a model with the sam key in the map/json ?