Commit 8e8f1b15 authored by 张宏's avatar 张宏

11

parent 5e6cf1be
......@@ -43,7 +43,7 @@ class AlertBasicInfoBO extends Equatable {
final int alertCount;
final String alertTime;
final String alertIcon;
final int alertDeviceId;
final String alertDeviceId;
const AlertBasicInfoBO({
required this.alertId,
......@@ -64,12 +64,12 @@ class AlertBasicInfoBO extends Equatable {
alertTitle: json['alertTitle'] as String? ?? '',
alertLevel: json['alertLevel'] as String? ?? '',
alertLevelText: json['alertLevelText'] as String? ?? '',
alertStatus: json['alertStatus'] as String? ?? '',
alertStatus: json['alertStatus']?.toString() ?? '',
alertDeviceLocation: json['alertDeviceLocation'] as String? ?? '',
alertCount: json['alertCount'] as int? ?? 0,
alertTime: json['alertTime'] as String? ?? '',
alertIcon: json['alertIcon'] as String? ?? '',
alertDeviceId: json['alertDeviceId'] as int? ?? 0,
alertDeviceId: json['alertDeviceId'] as String? ?? '',
);
}
......@@ -139,10 +139,30 @@ class DataPointBO extends Equatable {
});
factory DataPointBO.fromJson(Map<String, dynamic> json) {
final rawValue = json['value'];
final double value;
if (rawValue is num) {
value = rawValue.toDouble();
} else if (rawValue is String) {
value = double.tryParse(rawValue) ?? 0;
} else {
value = 0;
}
final rawRecordId = json['recordId'];
final int recordId;
if (rawRecordId is int) {
recordId = rawRecordId;
} else if (rawRecordId is String) {
recordId = int.tryParse(rawRecordId) ?? 0;
} else {
recordId = 0;
}
return DataPointBO(
time: json['time'] as String? ?? '',
value: (json['value'] as num?)?.toDouble() ?? 0,
recordId: json['recordId'] as int? ?? 0,
value: value,
recordId: recordId,
);
}
......
......@@ -118,10 +118,30 @@ class DeviceDataPointBO {
});
factory DeviceDataPointBO.fromJson(Map<String, dynamic> json) {
final rawPower = json['power'];
final double power;
if (rawPower is num) {
power = rawPower.toDouble();
} else if (rawPower is String) {
power = double.tryParse(rawPower) ?? 0;
} else {
power = 0;
}
final rawTemperature = json['temperature'];
final double temperature;
if (rawTemperature is num) {
temperature = rawTemperature.toDouble();
} else if (rawTemperature is String) {
temperature = double.tryParse(rawTemperature) ?? 0;
} else {
temperature = 0;
}
return DeviceDataPointBO(
time: json['time'] as String? ?? '',
power: (json['power'] as num?)?.toDouble() ?? 0,
temperature: (json['temperature'] as num?)?.toDouble() ?? 0,
power: power,
temperature: temperature,
);
}
}
\ No newline at end of file
......@@ -136,7 +136,8 @@ class AbnormalDetailView extends StatelessWidget {
),
child: TextButton(
onPressed: () {
final deviceId = cubit.state.alarmInfo?.alertDeviceId ?? 0;
final deviceIdStr = cubit.state.alarmInfo?.alertDeviceId ?? '';
final deviceId = int.tryParse(deviceIdStr) ?? 0;
context.pushRoute(DeviceDetailRoute(deviceId: deviceId));
},
child: Row(
......
......@@ -15,7 +15,7 @@ class AlarmInfo {
final String linkAction;
final String date;
final List<FlSpot> temperatureSpots;
final int alertDeviceId;
final String alertDeviceId;
const AlarmInfo({
required this.alarmType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment