fix:调整猫眼设置返回的数据类型不一致导致锁设置无法加载的问题
This commit is contained in:
parent
2fb2731011
commit
2afc6f4ac6
@ -502,6 +502,7 @@ class CatEyeConfig {
|
||||
|
||||
// 定义 CatEyeModeConfig 类
|
||||
class CatEyeModeConfig {
|
||||
// 构造函数
|
||||
CatEyeModeConfig({
|
||||
this.recordMode,
|
||||
this.recordTime,
|
||||
@ -511,25 +512,20 @@ class CatEyeModeConfig {
|
||||
this.detectionDistance,
|
||||
});
|
||||
|
||||
// 从 JSON 数据构造对象
|
||||
factory CatEyeModeConfig.fromJson(Map<String, dynamic> json) {
|
||||
// 工厂方法:从 JSON 数据构造对象
|
||||
factory CatEyeModeConfig.fromJson(Map<String, dynamic>? json) {
|
||||
if (json == null) return CatEyeModeConfig();
|
||||
|
||||
return CatEyeModeConfig(
|
||||
recordMode: json['recordMode'] != null ? int.tryParse(json['recordMode'].toString()) : null,
|
||||
recordTime: json['recordTime'],
|
||||
realTimeMode: json['realTimeMode'] != null ? int.tryParse(json['realTimeMode'].toString()) : null,
|
||||
recordEndTime: json['recordEndTime'] != null ? int.tryParse(json['recordEndTime'].toString()) : null,
|
||||
recordStartTime: json['recordStartTime'] != null ? int.tryParse(json['recordStartTime'].toString()) : null,
|
||||
detectionDistance: json['detectionDistance'],
|
||||
recordMode: _safeParseInt(json['recordMode']),
|
||||
recordTime: json['recordTime']?.toString(),
|
||||
realTimeMode: _safeParseInt(json['realTimeMode']),
|
||||
recordEndTime: _safeParseInt(json['recordEndTime']),
|
||||
recordStartTime: _safeParseInt(json['recordStartTime']),
|
||||
detectionDistance: json['detectionDistance']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
int? recordMode;
|
||||
String? recordTime;
|
||||
int? realTimeMode;
|
||||
int? recordEndTime;
|
||||
int? recordStartTime;
|
||||
String? detectionDistance;
|
||||
|
||||
// 将对象转换为 JSON 数据
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
@ -541,4 +537,31 @@ class CatEyeModeConfig {
|
||||
data['detectionDistance'] = detectionDistance;
|
||||
return data;
|
||||
}
|
||||
|
||||
// 属性定义
|
||||
int? recordMode; // 录制模式
|
||||
String? recordTime; // 录制时间
|
||||
int? realTimeMode; // 实时模式
|
||||
int? recordEndTime; // 录制结束时间
|
||||
int? recordStartTime; // 录制开始时间
|
||||
String? detectionDistance; // 检测距离
|
||||
|
||||
// 辅助方法:安全地将字符串解析为整数
|
||||
static int? _safeParseInt(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is int) return value; // 如果已经是 int,直接返回
|
||||
if (value is String) return int.tryParse(value); // 尝试解析字符串为整数
|
||||
return null; // 如果无法解析,返回 null
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'CatEyeModeConfig{'
|
||||
'recordMode: $recordMode, '
|
||||
'recordTime: $recordTime, '
|
||||
'realTimeMode: $realTimeMode, '
|
||||
'recordEndTime: $recordEndTime, '
|
||||
'recordStartTime: $recordStartTime, '
|
||||
'detectionDistance: $detectionDistance}';
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user