gpt4 book ai didi

Instantiate a hive object from json while preserving the key(从json实例化配置单元对象,同时保留密钥)

转载 作者:bug小助手 更新时间:2023-10-26 21:00:46 35 4
gpt4 key购买 nike



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工厂?


更多回答
优秀答案推荐
更多回答

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com