diff --git a/lib/scan_result.dart b/lib/scan_result.dart index 8f29805c..2e7d2b79 100644 --- a/lib/scan_result.dart +++ b/lib/scan_result.dart @@ -27,27 +27,25 @@ class ScanResult { /// A packet of data advertised by the peripheral. final AdvertisementData advertisementData; - + ScanResult._( - this.peripheral, + this.peripheral, this.rssi, - this.advertisementData, - {this.isConnectable, - List? overflowServiceUuids, + this.advertisementData, { + this.isConnectable, + List? overflowServiceUuids, }) : overflowServiceUuids = overflowServiceUuids ?? []; - factory ScanResult.fromJson( - Map json, - ManagerForPeripheral manager - ) { + Map json, ManagerForPeripheral manager) { assert(json[_ScanResultMetadata.rssi] is int); return ScanResult._( - Peripheral.fromJson(json, manager), + Peripheral.fromJson(json, manager), json[_ScanResultMetadata.rssi], AdvertisementData._fromJson(json), isConnectable: json[_ScanResultMetadata.isConnectable], - overflowServiceUuids: json[_ScanResultMetadata.overflowServiceUuids] + overflowServiceUuids: _mapToListOfStringsOrNull( + json[_ScanResultMetadata.overflowServiceUuids]), ); } } @@ -83,10 +81,8 @@ class AdvertisementData { _mapToListOfStringsOrNull(json[_ScanResultMetadata.serviceUuids]), localName = json[_ScanResultMetadata.localName], txPowerLevel = json[_ScanResultMetadata.txPowerLevel], - solicitedServiceUuids = - _mapToListOfStringsOrNull( - json[_ScanResultMetadata.solicitedServiceUuids] - ); + solicitedServiceUuids = _mapToListOfStringsOrNull( + json[_ScanResultMetadata.solicitedServiceUuids]); static Map? _getServiceDataOrNull( Map? serviceData) { @@ -106,3 +102,6 @@ class AdvertisementData { static List? _mapToListOfStringsOrNull(List? values) => values?.cast(); } + +List _mapToListOfStringsOrNull(List? values) => + (values ?? []).cast();