You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
class OtaConfigResp {
|
|
// 单例实例
|
|
static OtaConfigResp? _instance;
|
|
|
|
// 单例访问器(增加空安全保护)
|
|
static OtaConfigResp get instance {
|
|
if (_instance == null) {
|
|
throw Exception("User must be initialized first");
|
|
}
|
|
return _instance!;
|
|
}
|
|
|
|
// 最终属性(不可变)
|
|
final String? id;
|
|
final int? factory;
|
|
final int? devicetype;
|
|
final String? devicename;
|
|
final String? systemversion;
|
|
final String? updatepackageaddress;
|
|
final String? updatedescription;
|
|
// 私有构造函数
|
|
OtaConfigResp._({
|
|
this.id,
|
|
this.factory,
|
|
this.devicetype,
|
|
this.devicename,
|
|
this.systemversion,
|
|
this.updatepackageaddress,
|
|
this.updatedescription,
|
|
});
|
|
|
|
factory OtaConfigResp.fromJson(Map<String, dynamic> json) {
|
|
print("数据获取fronTokenJson${json}");
|
|
// 修复1:安全获取嵌套的 user 字段
|
|
final infoData = json['product'] as Map<String, dynamic>?; // 允许空值
|
|
|
|
// 更新单例实例
|
|
return _instance = OtaConfigResp._(
|
|
id: (infoData?['id'] as String?) ?? '',
|
|
factory: (infoData?['factoryid'] as int?) ?? 0,
|
|
devicetype: (infoData?['devicetype'] as int?) ?? 0,
|
|
devicename: (infoData?['devicename'] as String?) ?? '',
|
|
systemversion: (infoData?['systemversion'] as String?) ?? '',
|
|
updatepackageaddress:
|
|
(infoData?['updatepackageaddress'] as String?) ?? '',
|
|
updatedescription: (infoData?['updatedescription'] as String?) ?? '',
|
|
);
|
|
}
|
|
|
|
// 完整的JSON序列化
|
|
Map<String, dynamic> toJson() => {
|
|
'user': {
|
|
'id': instance.id,
|
|
'factory': instance.factory,
|
|
'devicetype': instance.devicetype,
|
|
'devicename': instance.devicename,
|
|
'systemversion': instance.systemversion,
|
|
'updatepackageaddress': instance.updatepackageaddress,
|
|
'updatedescription': instance.updatedescription,
|
|
}
|
|
};
|
|
}
|
|
|