From 2afc6f4ac61826ad068ca5eaf85a065a0dca6c8f Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 3 Mar 2025 10:04:53 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=B0=83=E6=95=B4=E7=8C=AB?= =?UTF-8?q?=E7=9C=BC=E8=AE=BE=E7=BD=AE=E8=BF=94=E5=9B=9E=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=B1=BB=E5=9E=8B=E4=B8=8D=E4=B8=80=E8=87=B4=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E9=94=81=E8=AE=BE=E7=BD=AE=E6=97=A0=E6=B3=95=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lockMian/entity/lockListInfo_entity.dart | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/main/lockMian/entity/lockListInfo_entity.dart b/lib/main/lockMian/entity/lockListInfo_entity.dart index 353fbeb9..754891c1 100755 --- a/lib/main/lockMian/entity/lockListInfo_entity.dart +++ b/lib/main/lockMian/entity/lockListInfo_entity.dart @@ -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 json) { + // 工厂方法:从 JSON 数据构造对象 + factory CatEyeModeConfig.fromJson(Map? 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 toJson() { final Map data = {}; @@ -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}'; + } }