Implement last heard display on device details

This commit is contained in:
2026-01-20 00:36:01 +01:00
parent b96214fcba
commit 4aa5fd156f
2 changed files with 227 additions and 27 deletions

View File

@@ -58,37 +58,55 @@ class LastHeardItem {
});
factory LastHeardItem.fromJson(Map<String, dynamic> json) {
int? _toInt(dynamic value) {
if (value == null) return null;
if (value is int) return value;
if (value is double) return value.toInt();
if (value is String) return int.tryParse(value);
return null;
}
String _toString(dynamic value) {
if (value == null) return '';
return value.toString();
}
String? _toStringOrNull(dynamic value) {
if (value == null) return null;
return value.toString();
}
return LastHeardItem(
linkName: json['LinkName'] as String? ?? '',
sessionID: json['SessionID'] as String? ?? '',
linkType: json['LinkType'] as int? ?? 0,
contextID: json['ContextID'] as int? ?? 0,
sessionType: json['SessionType'] as int? ?? 0,
slot: json['Slot'] as int? ?? 0,
sourceID: json['SourceID'] as int? ?? 0,
destinationID: json['DestinationID'] as int? ?? 0,
route: json['Route'] as String? ?? '',
linkCall: json['LinkCall'] as String? ?? '',
sourceCall: json['SourceCall'] as String? ?? '',
sourceName: json['SourceName'] as String?,
destinationCall: json['DestinationCall'] as String? ?? '',
destinationName: json['DestinationName'] as String?,
start: json['Start'] as int? ?? 0,
stop: json['Stop'] as int? ?? 0,
rssi: json['RSSI'] as int?,
ber: json['BER'] as int?,
reflectorID: json['ReflectorID'] as int? ?? 0,
linkTypeName: json['LinkTypeName'] as String? ?? '',
linkName: _toString(json['LinkName']),
sessionID: _toString(json['SessionID']),
linkType: _toInt(json['LinkType']) ?? 0,
contextID: _toInt(json['ContextID']) ?? 0,
sessionType: _toInt(json['SessionType']) ?? 0,
slot: _toInt(json['Slot']) ?? 0,
sourceID: _toInt(json['SourceID']) ?? 0,
destinationID: _toInt(json['DestinationID']) ?? 0,
route: _toString(json['Route']),
linkCall: _toString(json['LinkCall']),
sourceCall: _toString(json['SourceCall']),
sourceName: _toStringOrNull(json['SourceName']),
destinationCall: _toString(json['DestinationCall']),
destinationName: _toStringOrNull(json['DestinationName']),
start: _toInt(json['Start']) ?? 0,
stop: _toInt(json['Stop']) ?? 0,
rssi: _toInt(json['RSSI']),
ber: _toInt(json['BER']),
reflectorID: _toInt(json['ReflectorID']) ?? 0,
linkTypeName: _toString(json['LinkTypeName']),
callTypes: (json['CallTypes'] as List<dynamic>?)
?.map((e) => e as String)
?.map((e) => e.toString())
.toList() ??
[],
lossCount: json['LossCount'] as int? ?? 0,
totalCount: json['TotalCount'] as int? ?? 0,
master: json['Master'] as String? ?? '',
talkerAlias: json['TalkerAlias'] as String?,
flagSet: json['FlagSet'] as int? ?? 0,
event: json['Event'] as String? ?? '',
lossCount: _toInt(json['LossCount']) ?? 0,
totalCount: _toInt(json['TotalCount']) ?? 0,
master: _toString(json['Master']),
talkerAlias: _toStringOrNull(json['TalkerAlias']),
flagSet: _toInt(json['FlagSet']) ?? 0,
event: _toString(json['Event']),
);
}