When my class is extending HiveObject
I have access to key
using the getter defined in HiveObjectMixin
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
当我的类扩展HiveObject时,我可以使用HiveObjectMixin中定义的getter访问Key,但在通过网络将类实例作为JSON发送后,我需要使用Model.FromMap(Map<字符串,动态>map)将其转换回模型,但我不能设置Key,因为它是私有的,并且HiveObtMixin没有定义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 ?
我如何定义一个在map/json中返回带有Sam键的模型的from Map工厂?
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!