fix:调整猫眼设置返回的数据类型不一致导致锁设置无法加载的问题

This commit is contained in:
liyi 2025-03-03 10:04:53 +08:00
parent 2fb2731011
commit 2afc6f4ac6

View File

@ -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}';
}
}